表1
队员号
1
2
3
4
5
6
表2
队员号 国家
1 中国
1 中国
2 中国
2 中国
3 中国
4 法国
5 法国
6 德国
现有两个表格
目标:统计表1中队员号对应国家的数量。
结果:在表1中,中国队员3名,法国2名,德国1名
求教:SQL语句
------解决方案--------------------
select
国家,
count(distinct 队员号) as 人数
from table2
group by 国家
select
b.国家,
count(distinct a.队员号) as 人数
from table1 as a
inner join table2 as b on a.队员号=b.队员号
group by b.国家