Думаю можно сделать вьюху, с чем то подобным(не знаю какая у вас субд)
Select
post_id,
sum(case when mood == 'positive' then 1 else 0 end) as count_positive,
sum(case when mood == 'negative' then 1 else 0 end) as count_ negative
FROM Reviews
GROUP BY post_id
ну а потом как в статье
SELECT
widget_id,
((positive + 1.9208) / (positive + negative) -
1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) /
(positive + negative)) / (1 + 3.8416 / (positive + negative))
AS ci_lower_bound
FROM widgets WHERE positive + negative > 0
ORDER BY ci_lower_bound DESC;