안녕하세요. 세로로 되있는 데이터를 가로로 출력하고 싶은데 구현을 어떻게 하는지 몰라 문의 드립니다...
A일때 5, B일때 2의 값으로 표현하고 싶은데 제가 구현한 방법으로는 가로로 나오지 않네요...
SELECT
DECODE(LOCATION_ID, 'SLC017', NVL(WAIT_CNT, 0), 0) "SLC017",
DECODE(LOCATION_ID, 'SLC045', NVL(WAIT_CNT, 0), 0) "SLC045"
FROM
(SELECT
SL.LOCATION_ID,
COUNT(*) WAIT_CNT
FROM
SWC_OFFICE_USE_WAIT SOU,
SWC_OFFICE SO,
SWC_LOCATION SL
WHERE
SOU.OFFICE_ID = SO.OFFICE_ID
AND SL.LOCATION_ID = SO.SERVICE_LOCA_CODE
AND SOU.RESERVATION_DATE = '20210426'
AND SL.LOCATION_ID IN ('SLC023', 'SLC008', 'SLC013', 'SLC015', 'SLC012', 'SLC016', 'SLC049', 'SLC050', 'SLC021', 'SLC051', 'SLC052',
'SLC004', 'SLC045', 'SLC009', 'SLC017', 'SLC014', 'SLC002', 'SLC020', 'SLC011', 'SLC019', 'SLC030', 'SLC031', 'SLC032', 'SLC033', 'SLC034'
, 'SLC035', 'SLC036', 'SLC037', 'SLC038', 'SLC039', 'SLC040', 'SLC041', 'SLC042', 'SLC043', 'SLC044')
AND SOU.STATUS = '1'
GROUP BY
SL.LOCATION_ID)
GROUP BY LOCATION_ID;
가로 데이터
SLC017 | SLC045 | SLC009 | SLC013 |
5 | 2 | 3 | 7 |
SELECT COUNT(DECODE(sl.location_id, 'SLC017', 1) SLC017 , COUNT(DECODE(sl.location_id, 'SLC045', 1) SLC045 , COUNT(DECODE(sl.location_id, 'SLC009', 1) SLC009 , COUNT(DECODE(sl.location_id, 'SLC013', 1) SLC013 FROM swc_office_use_wait sou , swc_office so , swc_location sl WHERE sou.office_id = so.office_id AND sl.location_id = so.service_loca_code AND sl.location_id IN ('SLC017', 'SLC045', 'SLC009', 'SLC013') AND sou.reservation_date = '20210426' AND sou.status = '1' ;