sql - Select distinct values with count in PostgreSQL -


this heavily simplified version of sql problem i'm dealing with. let's i've got table of cities in world, this:

country city ------------ canada  montreal cuba    havanna china   beijing canada  victoria china   macau 

i want count how many cities each country has, end table such:

country city_count ------------------ canada  50 cuba    10 china   200 

i know can distinct country values select distinct country t1 , suspect need construct subquery city_count column. non-sql brain telling me need loop through results...

thanks!

assuming reason new row unique city

select country, count(country) city_count table group country 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -