0

我试图通过语句仅显示该组中最大的组;

SELECT COUNT(type) AS booking, type FROM booking b, room r WHERE r.rno = b.rno AND r.hno = b.hno GROUP BY type;

我修改了它,所以我们现在得到了这个查询响应,你可以看到双组比家庭大。

预订类型


     5 double
     2 family

我知道您可以添加一个 HAVING 关键字,以便仅显示与数字相比的计数,因此我可以执行 COUNT(type) HAVING > 2 或类似操作,但这不是很动态,并且仅在这种情况下有效,因为我知道两个金额。

4

4 回答 4

3

ORDER BY COUNT(type) DESC LIMIT 1

于 2013-08-22T00:55:51.093 回答
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;
于 2013-08-22T01:40:01.570 回答
1

只需订购您的查询..

通过预订描述订购

问候

于 2013-08-22T00:58:19.447 回答
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
于 2013-08-22T01:01:12.650 回答