我有两张桌子:
会议室 ID
访问次数:摆脱,评分
我想获得每个房间的重量等级(等级> 0)。
评分从1到10.评分0 =用户没有给房间评分,所以不要计算。
我怎么能得到它?
谢谢!
答案 0 :(得分:1)
试试这个
SELECT
rooms.id,
t1.count
FROM
rooms
INNER JOIN
(
SELECT
rid,
COUNT(rating) as count
FROM
visits
WHERE visits.rating <> 0
GROUP BY visits.rid
) AS t1 ON rooms.id = t1.rid