본문 바로가기
Data/SQL

MySQL Transpose

by DenverAlmighty 2023. 1. 25.
반응형

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
반응형