我试图只按声明显示该组中最大的组;
SELECT COUNT(type) AS booking, type FROM booking b, room r WHERE r.rno = b.rno AND r.hno = b.hno GROUP BY type;
我修改了它,所以我们得到了这个查询响应,现在你可以看到group double比family更大了。
预订类型
5 double
2 family
我知道你可以添加一个HAVING关键字,以便只显示与数字相比的数量,所以我可以做COUNT(类型)HAVING> 2或类似,但不是非常动态,只会在这种情况下起作用,因为我知道这两个数量。
答案 0 :(得分:3)
按COUNT排序(类型)DESC LIMIT 1
答案 1 :(得分:2)
没有having
语句可以执行此操作。但您可以将rownum
与子查询一起使用:
select t.*
from (SELECT COUNT(type) AS booking, type
FROM booking b join
room r
on r.rno = b.rno AND r.hno = b.hno
GROUP BY type
order by count(type) desc
) t
where rownum = 1;
答案 2 :(得分:1)
只需订购您的查询..
通过预订desc订购
问候
答案 3 :(得分:1)
尝试这个
SELECT COUNT(type) AS booking, type FROM booking b, room r WHERE r.rno = b.rno AND r.hno = b.hno ORDER BY type DESC LIMIT 1