나는 이렇게 학습한다/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

 

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

SQL Basics: Create a FUNCTION  (0) 2022.06.15
SQL with Street Fighter: Total Wins  (0) 2022.06.14
Keep Hydrated!  (0) 2022.06.12
Opposite number  (0) 2022.06.11
SQL with LOTR: Elven Wildcards  (0) 2022.06.10