나는 이렇게 학습한다/Algorithm & SQL

Easy SQL: Counting and Grouping

daco2020 2022. 6. 29. 20:15
반응형

Given a demographics table in the following format:

** demographics table schema **

  • id
  • name
  • birthday
  • race

you need to return a table that shows a count of each race represented, ordered by the count in descending order as:

** output table schema **

  • race
  • count

 

Solution:

SELECT 
  race, 
  COUNT(id) 
FROM 
  demographics 
GROUP BY race 
ORDER BY count DESC

 

 

Result:

race count
American Indian or Alaska Native 23
Asian 22
White 19
Black or African American 18

 

 

반응형