我有一个名为“房间”的表名,上面有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)但我的问题是,我只想要一个来自租赁的最大数字,它有最大的匹配值,输出如上面的above.in查询将接受一个条件,如count(*) >1。但我想检查租赁列中的所有行,而不是它的条件。
发布于 2016-07-21 16:45:23
使用ORDER BY和LIMIT 1
select count(*) as cnt,rental from room group by rental order by cnt DESC limit 1;https://stackoverflow.com/questions/38499223
复制相似问题