我有一个MySQL表格,其中包含以下数据:
country | city
---------------
italy | milan
italy | rome
italy | rome
ireland | cork
uk | london
ireland | cork
我想查询并按照国家和城市进行分组,并统计城市和国家的数量,就像这样:
country | city | city_count | country_count
---------------------------------------------
ireland | cork | 2 | 2
italy | milan | 1 | 3
italy | rome | 2 | 3
uk | london | 1 | 1
我可以做到:
SELECT country, city, count(city) as city_count
FROM jobs
GROUP BY country, city
这让我有了:
country | city | city_count
-----------------------------
ireland | cork | 2
italy | milan | 1
italy | rome | 2
uk | london | 1
有指导如何获取country_count的指针吗?