반응형
Before
NAME | Subject | Grade |
Den | History | A |
River | History | B |
Paris | History | C |
River | Math | A |
Den | Math | B |
Jay | Math | C |
SELECT
Subject,
MAX(IF(Grade = 'A', Name, NULL)) AS A,
MAX(IF(Grade = 'B', Name, NULL)) AS B,
MAX(IF(Grade = 'C', Name, NULL)) AS C,
FROM TABLE
GROUP BY Subject;
After
Subject | A | B | C |
History | Den | River | Paris |
Math | River | Den | Jay |
어렵게 생각하다가 시간을 많이 썼다..
728x90
반응형
'Data > SQL' 카테고리의 다른 글
[프로그래머스] Lv1 ~Lv.4 with, exists (0) | 2024.05.05 |
---|---|
[프로그래머스] SELECT (MySQL) (0) | 2023.01.24 |
[프로그래머스] String, Date (MySQL) (0) | 2023.01.24 |
[프로그래머스] GROUP BY (MySQL) (0) | 2023.01.22 |
[프로그래머스] JOIN (MySQL) (0) | 2023.01.22 |