Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL return multiple count statements

Tags:

sql

count

I have a table which contains ski resorts around the world. The table also identifies which country and "sector" (USA/Europe/Asia etc.) they are located in. I'm trying to determine the number of resorts in each sector.

Sample Data :

resort_id, resort_name, country_id, sector_id
3376    Chréa           204  204
3377    Tikjda          204  204
3384    Beidahu         208  205
3481    Canyon Ski Area 225  206
3482    Castle Mountain 225  206
3483    Drumheller      225  206

I need to be able to determine the number of resorts in each sector i.e. :

Sector       Resorts
--------------------
204          2
205          1
206          3

Any help would be much appreciated thanks.

like image 945
Jonnie Avatar asked May 02 '26 15:05

Jonnie


1 Answers

select sector_id,
       count(*)
from   resortTableName
group by sector_id

and to address your edited question:

select sector_id,
       count(distinct resort_name) as resortCount,
       count(distinct country_id) as countryCount
from   resortTableName
group by sector_id
like image 145
paul Avatar answered May 04 '26 03:05

paul