SQL
[SQL] 프로그래머스 GROUP BY : 언어별 개발자 분류하기 (level 4) - 2회차 복습 완료
민아당긴아
2024. 7. 3. 17:34
💡문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/276036
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
💡SQL 코드 설계
GRADE가 각각 A, B, C가 되는 조건을 파악하고 CASE WHEN 구문으로 조건을 만든다.
- A : Front End 스킬과 Python 스킬을 함께 가지고 있는 개발자
SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0 AND SKILL_CODE & (select code from skillcodes where name = "Python") > 0
- B : C# 스킬을 가진 개발자
SKILL_CODE & (select code from skillcodes where name = "C#") > 0
- C : 그 외의 Front End 개발자
SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0
💡SQL 코드
-- 코드를 작성해주세요
SELECT
CASE
WHEN SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0 AND SKILL_CODE & (select code from skillcodes where name = "Python") > 0 THEN "A"
WHEN SKILL_CODE & (select code from skillcodes where name = "C#") > 0 THEN "B"
WHEN SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0 THEN "C"
END AS GRADE,
ID, EMAIL
FROM
DEVELOPERS
WHERE
CASE
WHEN SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0 AND SKILL_CODE & (select code from skillcodes where name = "Python") > 0 THEN "A"
WHEN SKILL_CODE & (select code from skillcodes where name = "C#") > 0 THEN "B"
WHEN SKILL_CODE & (select sum(code) from skillcodes where category = "Front End") > 0 THEN "C"
END IS NOT NULL
ORDER BY
GRADE, ID
💡기억할 내용
1. WHERE 절에 CASE WHEN으로 만든 필드명을 쓸 수 없으니, CASE WHEN문을 그대로 다시 써줘야 한다.
2. CASE WHEN할 때 조건 앞에 매번 WHEN을 붙여줘야 한다.