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

SQL Basics: Simple GROUP BY

daco2020 2022. 6. 13. 21:06

For this challenge you need to create a simple GROUP BY statement, you want to group all the people by their age and count the people who have the same age.

people table schema

  • id
  • name
  • age

select table schema

  • age [group by]
  • people_count (people count)

 

Solution:

SELECT 
  age, 
  COUNT(age) AS people_count 
FROM 
  people 
GROUP BY 
  age

 

 

Result:

age people_count
8 10
4 7
1 16
5 8
3 7
0 9
9 13
6 12