正确使用count(*)和group by函数

时间:2013-01-12 01:27:00

标签: sql

在sql中你可以使用GROUP BY函数和像国家一样的列吗? (这将是一个char / varchar)

SELECT country, population, COUNT(*) AS count_cities
FROM list_of_cities
GROUP BY country;

什么是更好的方式来写这个?

1 个答案:

答案 0 :(得分:3)

SELECT country, SUM(population) AS country_population, COUNT(*) AS count_cities 
FROM list_of_cities 
GROUP BY country;