안녕하세요
매우 오랜만입니다
손 풀겸 SQL로 찾아왔습니다.
https://school.programmers.co.kr/learn/courses/30/lessons/284527
WITH TMP AS (
SELECT EMP_NO
,SUM(SCORE) SCORE
FROM HR_GRADE G
WHERE G.YEAR = 2022
GROUP BY EMP_NO
ORDER BY SCORE DESC
LIMIT 1
)
SELECT SCORE
,E.EMP_NO
,EMP_NAME
,POSITION
,EMAIL
FROM HR_EMPLOYEES E INNER JOIN TMP T
ON E.EMP_NO = T.EMP_NO
WITH TMP AS (
SELECT EMP_NO
,SUM(SCORE) SCORE
FROM HR_GRADE G
WHERE G.YEAR = 2022
GROUP BY EMP_NO
ORDER BY SCORE DESC
LIMIT 1
)
SELECT SCORE
,E.EMP_NO
,EMP_NAME
,POSITION
,EMAIL
FROM HR_EMPLOYEES E INNER JOIN TMP T
ON E.EMP_NO = T.EMP_NO;
https://school.programmers.co.kr/learn/courses/30/lessons/284528
WITH EMP_SCORE AS (
SELECT EMP_NO
,CASE WHEN AVG(SCORE) >= 96 THEN 'S'
WHEN AVG(SCORE) >= 90 THEN 'A'
WHEN AVG(SCORE) >= 80 THEN 'B'
ELSE 'C' END GRADE
FROM HR_GRADE
GROUP BY EMP_NO
)
SELECT E.EMP_NO
,EMP_NAME
,GRADE
,CASE WHEN GRADE = 'S' THEN SAL*0.2
WHEN GRADE = 'A' THEN SAL*0.15
WHEN GRADE = 'B' THEN SAL*0.1
ELSE 0 END BONUS
FROM HR_EMPLOYEES E INNER JOIN EMP_SCORE S
ON E.EMP_NO = S.EMP_NO
ORDER BY E.EMP_NO;
WITH EMP_SCORE AS (
SELECT EMP_NO
,CASE WHEN AVG(SCORE) >= 96 THEN 'S'
WHEN AVG(SCORE) >= 90 THEN 'A'
WHEN AVG(SCORE) >= 80 THEN 'B'
ELSE 'C' END GRADE
FROM HR_GRADE
GROUP BY EMP_NO
)
SELECT E.EMP_NO
,EMP_NAME
,GRADE
,CASE WHEN GRADE = 'S' THEN SAL*0.2
WHEN GRADE = 'A' THEN SAL*0.15
WHEN GRADE = 'B' THEN SAL*0.1
ELSE 0 END BONUS
FROM HR_EMPLOYEES E INNER JOIN EMP_SCORE S
ON E.EMP_NO = S.EMP_NO
ORDER BY E.EMP_NO;
To. 프로그래머스
좀 더 강한 문제들로 가지고 오도록.
내일은 알고리즘으로 찾아오겠습니다.
부족한 글 읽어주셔서 감사합니다.
잘못된 부분 혹은 개선할만한 부분에 대한 댓글 항상 환영합니다.