我需要帮助才能找到所有更好产品的平均评分

时间:2018-12-08 20:47:50

标签: sql sql-server tsql

id  year category_id    rating  avg_better

需要帮助找到所有更好产品的平均评分

1 个答案:

答案 0 :(得分:0)

select *,
 ( select avg(rating) 
   from mytab as t2
   where t2.year = t1.year     -- same year
     and t2.rating > t1.rating -- better rating
 ) as avg_better
from mytab as t1