简体   繁体   English

获取mysql数据库中记录的最大项目数

[英]Get maximum number of items recorded in mysql database

I've a Mysql table called "roomrent" which have following structure: 我有一个名为“roomrent”的Mysql表,其结构如下:

Id     city           country
----------------------------------
1      Dhaka          Bangladesh
2      Dhaka          Bangladesh
3      Washington     United States 
4      Paris          France
5      Dhaka          Bangladesh
6      Paris          France

I want to show 5 cities from DB which are recorded maximum time. 我想显示DB中记录最长时间的5个城市。 Like: in this table Dhaka is recoded maximum time. 喜欢:在这张表中, 达卡被记录为最长时间。

So it's should be show like this: 所以它应该像这样显示:

Dhaka
Paris
Washington
and other.....

How do i get this with mysql query ? 我怎么用mysql查询得到这个? I know it's can be done by mysql Select query , But I can't. 我知道它可以通过mysql 选择查询来完成,但我不能。

Note: I'm new in php & mysql and It's my learning time. 注意:我是php和mysql的新手,这是我的学习时间。

Any help greatly appreciated. 任何帮助非常感谢。
Thanks 谢谢

You should be able to use the following. 您应该能够使用以下内容。 Which gets a count of the cities that appear in your table and will return the top 5: 其中列出了您的表格中显示的城市数量,并将返回前5名:

select city, count(city) Total
from roomrent
group by city
order by total desc
limit 0, 5

See SQL Fiddle with Demo 请参阅SQL Fiddle with Demo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM