원본 데이터
일자 | 환자수 | 검사실 |
2020-06-01 | 6 | 검사실0 |
2020-06-01 | 74 | 검사실1 |
2020-06-01 | 23 | 검사실2 |
2020-06-01 | 4 | 검사실3 |
2020-06-01 | 7 | 검사실4 |
2020-06-01 | 9 | 검사실5 |
2020-06-01 | 20 | 검사실6 |
2020-06-02 | 5 | 검사실0 |
2020-06-02 | 80 | 검사실1 |
2020-06-02 | 20 | 검사실2 |
2020-06-02 | 2 | 검사실3 |
2020-06-02 | 6 | 검사실4 |
2020-06-02 | 5 | 검사실5 |
2020-06-02 | 15 | 검사실6 |
2020-06-03 | 7 | 검사실0 |
2020-06-03 | 83 | 검사실1 |
2020-06-03 | 22 | 검사실2 |
2020-06-03 | 2 | 검사실3 |
2020-06-03 | 7 | 검사실4 |
2020-06-03 | 3 | 검사실5 |
2020-06-03 | 17 | 검사실6 |
위의 형태를 아래와 같이 데이터를 조회하고 싶은데...
일자 | 검사실0 | 검사실1 | 검사실2 | 검사실3 | 검사실4 | 검사실5 | 검사실6 |
2020-06-01 | 6 | 74 | 23 | 4 | 7 | 9 | 20 |
2020-06-02 | 5 | 80 | 20 | 2 | 6 | 5 | 15 |
2020-06-03 | 7 | 83 | 22 | 2 | 7 | 3 | 17 |
혼자서 이방법 저방법 해보다가 ㅠㅠ 도저히 답이 안나와서 ..여쭤보아요..
너무 답답해서 ... 궁금하기도 하고... 좀 도와주세요.ㅠㅠ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | WITH TAB AS ( SELECT '2020-06-01' DT ,6 CNT , '검사실0' PLC FROM DUAL UNION ALL SELECT '2020-06-01' ,74, '검사실1' FROM DUAL UNION ALL SELECT '2020-06-01' ,23, '검사실2' FROM DUAL UNION ALL SELECT '2020-06-01' ,4, '검사실3' FROM DUAL UNION ALL SELECT '2020-06-01' ,7, '검사실4' FROM DUAL UNION ALL SELECT '2020-06-01' ,9, '검사실5' FROM DUAL UNION ALL SELECT '2020-06-01' ,20, '검사실6' FROM DUAL UNION ALL SELECT '2020-06-02' ,5, '검사실0' FROM DUAL UNION ALL SELECT '2020-06-02' ,80, '검사실1' FROM DUAL UNION ALL SELECT '2020-06-02' ,20, '검사실2' FROM DUAL UNION ALL SELECT '2020-06-02' ,2, '검사실3' FROM DUAL UNION ALL SELECT '2020-06-02' ,6, '검사실4' FROM DUAL UNION ALL SELECT '2020-06-02' ,5, '검사실5' FROM DUAL UNION ALL SELECT '2020-06-02' ,15, '검사실6' FROM DUAL UNION ALL SELECT '2020-06-03' ,7, '검사실0' FROM DUAL UNION ALL SELECT '2020-06-03' ,83, '검사실1' FROM DUAL UNION ALL SELECT '2020-06-03' ,22, '검사실2' FROM DUAL UNION ALL SELECT '2020-06-03' ,2, '검사실3' FROM DUAL UNION ALL SELECT '2020-06-03' ,7, '검사실4' FROM DUAL UNION ALL SELECT '2020-06-03' ,3, '검사실5' FROM DUAL UNION ALL SELECT '2020-06-03' ,17, '검사실6' FROM DUAL ) SELECT * FROM TAB PIVOT ( SUM (CNT) FOR PLC IN ( '검사실0' , '검사실1' , '검사실2' , '검사실3' , '검사실4' , '검사실5' , '검사실6' ) ) ORDER BY DT; |
주의하실 것은 검사실 리스트가 정확히 IN 안에 들어가야한다는 점입니다.