[596_EASY] Classes More Than 5 Students

2022. 10. 4. 19:43·SQL/LeetCode

Table: Courses

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| student     | varchar |
| class       | varchar |
+-------------+---------+
(student, class) is the primary key column for this table.
Each row of this table indicates the name of a student and the class in which they are enrolled.

 

Write an SQL query to report all the classes that have at least five students.

Return the result table in any order.

The query result format is in the following example.

 

Example 1:

Input: 
Courses table:
+---------+----------+
| student | class    |
+---------+----------+
| A       | Math     |
| B       | English  |
| C       | Math     |
| D       | Biology  |
| E       | Math     |
| F       | Computer |
| G       | Math     |
| H       | Math     |
| I       | Math     |
+---------+----------+
Output: 
+---------+
| class   |
+---------+
| Math    |
+---------+
Explanation: 
- Math has 6 students, so we include it.
- English has 1 student, so we do not include it.
- Biology has 1 student, so we do not include it.
- Computer has 1 student, so we do not include it.

 

문제 풀이

select class
from courses 
group by class
having count(*) >= 5
저작자표시 (새창열림)

'SQL > LeetCode' 카테고리의 다른 글

[603#_EASY]Consecutive Available Seats  (0) 2022.10.29
[597_EASY] Friend Requests I : Overall Acceptance Rate  (0) 2022.10.04
[595_EASY] Big Countries  (0) 2022.10.03
[586_EASY] Customer Placing the Largest Number of Orders  (0) 2022.10.03
[584_EASY] Find Customer Referee  (0) 2022.10.03
'SQL/LeetCode' 카테고리의 다른 글
  • [603#_EASY]Consecutive Available Seats
  • [597_EASY] Friend Requests I : Overall Acceptance Rate
  • [595_EASY] Big Countries
  • [586_EASY] Customer Placing the Largest Number of Orders
소금깨
소금깨
  • 소금깨
    고군분투 인생살이
    소금깨
  • 전체
    오늘
    어제
    • 분류 전체보기 (328)
      • SQL (271)
        • 프로그래머스 (27)
        • LeetCode (198)
        • Hacker Rank (27)
        • Solve SQL (1)
        • 개념 (15)
      • 데이터 분석 (16)
        • 참고하며 공부하기 (14)
      • 기타 (15)
        • 통계 (14)
      • 오류 (6)
      • 인생살이 (0)
        • 리뷰 (0)
        • 일기 (0)
      • 中文 (0)
      • TABLEAU (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    파이썬을활용한시계열데이터분석
    Hard
    medium
    프리미엄
    easy
    시계열데이터분석
    파이썬을활용한시계열데이터분석AtoZ올인원패키지Online
    HACKER_RANK
    LeetCode
    MySQL
    직장인인강
    group by
    프로그래머스
    패스트캠퍼스후기
    SQL
    직장인자기계발
    패스트캠퍼스
    solvesql
    해커랭크
    패캠챌린지
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
소금깨
[596_EASY] Classes More Than 5 Students
상단으로

티스토리툴바