코드로 우주평화

SQL Basics: Simple HAVING 본문

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

SQL Basics: Simple HAVING

daco2020 2022. 7. 19. 19:20

For this challenge you need to create a simple HAVING statement, you want to count how many people have the same age and return the groups with 10 or more people who have that age.

people table schema

  • id
  • name
  • age

return table schema

  • age
  • total_people

 

Solution:

SELECT 
  age,
  COUNT(age) AS total_people
FROM 
  people
GROUP BY
  age
HAVING
  COUNT(age) >= 10

 

 

Result:

age total_people
16 13
54 11
47 14
99 11
46 20

 

 

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

Sum of all the multiples of 3 or 5  (0) 2022.07.20
SQL Basics: Simple JOIN with COUNT  (0) 2022.07.19
Hello SQL World!  (0) 2022.07.17
GROCERY STORE: Logistic Optimisation  (0) 2022.07.16
SQL: Regex Replace  (0) 2022.07.15