SELECT IFSC_ID, 
       AVG(DECODE(STAT_HM, '0000', DECODE(SPED, NULL, 0, SPED),      0)) AS S00,              
       MIN(DECODE(STAT_HM, '0000', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G00,              
       AVG(DECODE(STAT_HM, '0100', DECODE(SPED, NULL, 0, SPED),      0)) AS S01,              
       MIN(DECODE(STAT_HM, '0100', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G01,              
       AVG(DECODE(STAT_HM, '0200', DECODE(SPED, NULL, 0, SPED),      0)) AS S02,              
       MIN(DECODE(STAT_HM, '0200', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G02,              
       AVG(DECODE(STAT_HM, '0300', DECODE(SPED, NULL, 0, SPED),      0)) AS S03,              
       MIN(DECODE(STAT_HM, '0300', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G03,              
       AVG(DECODE(STAT_HM, '0400', DECODE(SPED, NULL, 0, SPED),      0)) AS S04,              
       MIN(DECODE(STAT_HM, '0400', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G04,              
       AVG(DECODE(STAT_HM, '0500', DECODE(SPED, NULL, 0, SPED),      0)) AS S05,              
       MIN(DECODE(STAT_HM, '0500', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G05,              
       AVG(DECODE(STAT_HM, '0600', DECODE(SPED, NULL, 0, SPED),      0)) AS S06,              
       MIN(DECODE(STAT_HM, '0600', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G06,              
       AVG(DECODE(STAT_HM, '0700', DECODE(SPED, NULL, 0, SPED),      0)) AS S07,              
       MIN(DECODE(STAT_HM, '0700', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G07,              
       AVG(DECODE(STAT_HM, '0800', DECODE(SPED, NULL, 0, SPED),      0)) AS S08,              
       MIN(DECODE(STAT_HM, '0800', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G08,              
       AVG(DECODE(STAT_HM, '0900', DECODE(SPED, NULL, 0, SPED),      0)) AS S09,              
       MIN(DECODE(STAT_HM, '0900', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G09,              
       AVG(DECODE(STAT_HM, '1000', DECODE(SPED, NULL, 0, SPED),      0)) AS S10,              
       MIN(DECODE(STAT_HM, '1000', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G10,              
       AVG(DECODE(STAT_HM, '1100', DECODE(SPED, NULL, 0, SPED),      0)) AS S11,              
       MIN(DECODE(STAT_HM, '1100', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G11,              
       AVG(DECODE(STAT_HM, '1200', DECODE(SPED, NULL, 0, SPED),      0)) AS S12,              
       MIN(DECODE(STAT_HM, '1200', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G12,              
       AVG(DECODE(STAT_HM, '1300', DECODE(SPED, NULL, 0, SPED),      0)) AS S13,              
       MIN(DECODE(STAT_HM, '1300', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G13,              
       AVG(DECODE(STAT_HM, '1400', DECODE(SPED, NULL, 0, SPED),      0)) AS S14,              
       MIN(DECODE(STAT_HM, '1400', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G14,              
       AVG(DECODE(STAT_HM, '1500', DECODE(SPED, NULL, 0, SPED),      0)) AS S15,              
       MIN(DECODE(STAT_HM, '1500', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G15,              
       AVG(DECODE(STAT_HM, '1600', DECODE(SPED, NULL, 0, SPED),      0)) AS S16,              
       MIN(DECODE(STAT_HM, '1600', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G16,              
       AVG(DECODE(STAT_HM, '1700', DECODE(SPED, NULL, 0, SPED),      0)) AS S17,              
       MIN(DECODE(STAT_HM, '1700', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G17,              
       AVG(DECODE(STAT_HM, '1800', DECODE(SPED, NULL, 0, SPED),      0)) AS S18,              
       MIN(DECODE(STAT_HM, '1800', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G18,              
       AVG(DECODE(STAT_HM, '1900', DECODE(SPED, NULL, 0, SPED),      0)) AS S19,              
       MIN(DECODE(STAT_HM, '1900', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G19,              
       AVG(DECODE(STAT_HM, '2000', DECODE(SPED, NULL, 0, SPED),      0)) AS S20,              
       MIN(DECODE(STAT_HM, '2000', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G20,              
       AVG(DECODE(STAT_HM, '2100', DECODE(SPED, NULL, 0, SPED),      0)) AS S21,              
       MIN(DECODE(STAT_HM, '2100', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G21,              
       AVG(DECODE(STAT_HM, '2200', DECODE(SPED, NULL, 0, SPED),      0)) AS S22,              
       MIN(DECODE(STAT_HM, '2200', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G22,              
       AVG(DECODE(STAT_HM, '2300', DECODE(SPED, NULL, 0, SPED),      0)) AS S23,              
       MIN(DECODE(STAT_HM, '2300', DECODE(GRAD, NULL, 0, GRAD), 'LTC0')) AS G23     
  FROM (          
        SELECT A.IFSC_ID, A.STAT_HM, A.SPED, A.TRVL_HH, NVL(B.CMTR_GRAD_CD, 'LTC0') AS GRAD
          FROM TB_IFSC_HH_PTRN   A,
               TB_CMTR_GRAD_CLSF B, 
               TB_IFSC           C
         WHERE A.STAT_YM = '201801'
           AND A.DAY_TYPE_CD = 'DTW1'
           AND A.IFSC_ID IN (SELECT B.IFSC_ID AS IFSC_ID
                               FROM TB_ATRD_ROAD_RLTN A, TB_ROAD_IFSC_RLTN B, TB_IFSC C
                              WHERE A.ROAD_ID = B.ROAD_ID
                                AND B.IFSC_ID = C.IFSC_ID
                                AND A.ATRD_ID  IN (SELECT ATRD_ID FROM TB_ATRD WHERE TRIM(ATRD_NM) = '±¹µµ46È£¼±')
                              GROUP BY B.IFSC_ID)
           AND A.IFSC_ID      = C.IFSC_ID
           AND B.SECT_GRAD_CD = C.SECT_GRAD_CD
           AND (A.SPED >= B.LWST_TRVL_SPED AND A.SPED <= B.HGHS_TRVL_SPED)
       )
 GROUP BY IFSC_ID
