我编写以下代码来计算业务的平均评级,现在我想要业务类别中的TOP 2业务,我尝试添加HAVING COUNT(*) <= 2
,但它不起作用...
SELECT r.Bussiness_ID, b.Bussiness_Name, c.Catg_name, AVG(r.Rating)
FROM review r,bussiness b, busn_catg c
WHERE b.Bussiness_ID = r.Bussiness_ID
AND b.Category = c.Catg_ID
GROUP BY r.Bussiness_ID,b.Bussiness_Name, c.Catg_name
ORDER BY c.Catg_name, AVG(r.Rating);
答案 0 :(得分:0)
SELECT r.Bussiness_ID, b.Bussiness_Name, c.Catg_name, AVG(r.Rating) rt FROM review r,bussiness b, busn_catg c WHERE b.Bussiness_ID = r.Bussiness_ID AND b.Category = c.Catg_ID GROUP BY r.Bussiness_ID,b.Bussiness_Name, c.Catg_name ORDER BY c.Catg_name, rt desc;