简体   繁体   English

MySQL-分类和计数项目

[英]MySQL - assort and count items

My table has three columns 'name', 'city' and 'country'. 我的表有三列“名称”,“城市”和“国家”。 Now I want to make a list with only those countries, which has at least 3 times the SAME city. 现在,我只想列出那些国家的名单,这些国家的市值至少是同一个城市的3倍。

 name        city        country
 ----        ----        -------
 Smith       Boston      USA
 Wayne       St. Louis   USA
 Miller      Houston     USA
 Joseph      Houston     USA
 Obama       Washington  USA
 Jones       Houston     USA

 Sarkozy     Paris       France
 Merle       Paris       France
 Gabin       Marseille   France
 Delon       Avignon     France
 Deneuve     Avignon     France

 Trappatoni  Rome        Italy
 Linguini    Milano      Italy
 Mastroianni Rome        Italy

 Meier       Hamburg     Germany
 Müller      Munich      Germany
 Schmidt     Hamburg     Germany
 Böttcher    Hamburg     Germany
 Kunau       Hannover    Germany
 Wilhelm     Munich      Germany
 -------------------------------

                         USA
 Result:             
                         Germany

I tried it with distinct, count, group by etc. But without results. 我尝试了与众不同,计数,分组等等。但是没有结果。

Group by country and city then take only those having at least 3 entries each. 然后按国家和城市分组,然后仅接受每个条目至少包含3个条目的条目。

select distinct country
from your_table
group by country, city
having count(*) >= 3

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

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