我有一个像这样的桌子:
Id Subdistrict District
-----------------------------
1 K S
2 K S
3 M S
4 J B
5 J B
如果相同的街道(以及地区)值将计为1,我希望它返回这样的结果:
街道= 3(因为只有K,M和J街道)
区= 2(因为只有S和B区)
如何编写sql查询?在此先感谢:)
答案 0 :(得分:2)
尝试以下查询:
SELECT COUNT(DISTINCT Subdistrict) AS number_of_subdistricts,
COUNT(DISTINCT District) AS number_of_districts
FROM your_table