MySQL计数基于特定标准

时间:2015-04-08 07:28:03

标签: mysql

我有一个MYSQL数据集,如下所示:

表格

City
Country
CountryLanguage
...

以下查询获取欧洲每个地区的结果

2a:select DISTINCT Region from Country where Continent="Europe"

我现在需要查询的是:

  

对于每个地区,显示该地区的国家/地区数量

我尝试了一些事情,其中​​没有一个有效 - 我不知道,是否有人可以给我任何指示?

(表架构)

ID | Name  | Continent     | Region
1  | Aruba | North America | Carribean

1 个答案:

答案 0 :(得分:0)

您可以使用此查询 -

select continent, region, count(*) as "No of Country"  from Country where continent like 'Europe' group by region;

如果您想要变更

,此查询可以为您提供更多帮助
select continent, region, group_concat(Name) as "List of Country" ,count(*) as "No of Country"  from Country where continent like 'Europe' group by region;