DATE | SPED
20140723010000 | 10
20140723020000 | 20
20140723030000 | 30
20140723040000 | 40
20140723050000 | 50
결과
컬럼명(시간) 01 | 02 | 03 | 04 | 05 | 06
SPED 10 20 30 40 50 0
이런 결과을 얻고 싶은데 잘안되네요 ㅜㅜ
DATE 컬럼은 년월일시분초를 나타내어 매일 변하고 각 시간대별 스피드를 구하고 싶은데
아직 오라클을 시작하는지라 많이 어렵네요
WITH t AS ( SELECT '20140723010000' dt, 10 sped FROM dual UNION ALL SELECT '20140723020000', 20 FROM dual UNION ALL SELECT '20140723030000', 30 FROM dual UNION ALL SELECT '20140723040000', 40 FROM dual UNION ALL SELECT '20140723050000', 50 FROM dual ) SELECT 'SPED' gb , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '01', sped)), 0) "01" , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '02', sped)), 0) "02" , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '03', sped)), 0) "03" , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '04', sped)), 0) "04" , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '05', sped)), 0) "05" , NVL(MIN(DECODE(SUBSTR(dt, 9, 2), '06', sped)), 0) "06" FROM t WHERE dt LIKE '20140723%' ;