在sql中你可以使用GROUP BY函数和像国家一样的列吗? (这将是一个char / varchar)
SELECT country, population, COUNT(*) AS count_cities
FROM list_of_cities
GROUP BY country;
什么是更好的方式来写这个?
答案 0 :(得分:3)
SELECT country, SUM(population) AS country_population, COUNT(*) AS count_cities
FROM list_of_cities
GROUP BY country;