gpt4 book ai didi

MySQL - 分类和计数项目

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:06 26 4
gpt4 key购买 nike

我的表格有三列“名称”、“城市”和“国家/地区”。现在我想只列出那些至少有 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

我尝试了 distinct、count、group by 等,但没有结果。

最佳答案

然后按国家和城市分组,然后只取那些至少有 3 个条目的。

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

关于MySQL - 分类和计数项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28024920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com