我有一个桌子名称' room'有room_id和租赁。
mysql> select * from room;
+---------+--------+
| room_id | rental |
+---------+--------+
| 1 | 2000 |
| 2 | 1890 |
| 3 | 1832 |
| 4 | 1833 |
| 5 | 1850 |
| 6 | 1700 |
| 7 | 2100 |
| 8 | 2000 |
| 9 | 2000 |
| 10 | 2000 |
+----------+--------+
10 rows in set (0.00 sec)
我尝试在租借列中找到最大匹配行并计入数字。
mysql> select count(*),rental from room group by rental having count(*) >1;
+----------+--------+
| count(*) | rental |
+----------+--------+
| 4 | 2000 |
+----------+--------+
1 row in set (0.08 sec)
但我的问题是我只想要租赁中只有一个最大匹配值和输出如上所述的最大数字。在上面的查询中将采用像count(*)>这样的条件。 1.但我想检查租赁栏中的所有行而不是条件。
答案 0 :(得分:2)
使用命令和限制1
select count(*) as cnt,rental from room group by rental order by cnt DESC limit 1;