我的数据库中有下表
Name | total_stars | total_reviews
Item A 27 7
Item B 36 9
Item C 27 7
Item D 30 6
Item E 0 0
Item F 0 0
Item F 15 3
我正在看这篇文章,并试图在 postgresql 数据库中实现贝叶斯排名。
给出的排名公式是
br = ( (avg_num_votes * avg_rating) + (this_num_votes * this_rating) ) /
(avg_num_votes + this_num_votes)
在哪里:
- avg_num_votes:所有num_votes>0的项目的平均票数
- avg_rating:每个项目的平均评分(同样,那些有 num_votes>0 的项目)
- this_num_votes:该项目的投票数
- this_rating:这个项目的评分
这是我提出的查询,但它不起作用:
with avg_num_votes as (
select AVG(total_reviews)
from business
where total_reviews != 0),
avg_rating as (
select AVG(total_stars/total_reviews)
from business
where total_reviews != 0)
select * from business
order by ((avg_num_votes * avg_rating) + (total_stars)) / (avg_num_votes + total_reviews);
我正进入(状态:ERROR: column "avg_num_votes" does not exist