2013-01-12 28 views
1

在sql中你可以使用一個GROUP BY函數與列像國家? (這將是一個字符/ varchar)正確使用計數(*)與按功能分組

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

什麼是更好的方式來寫這個?

+0

「什麼是更好的書寫方式」 - 但是你想要做什麼? –

+0

我只是想了解count(*)與count(column_name)的用法,並找出一個與其他人不同的方法。感謝幫助。 – jdamae

回答

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