SELECT X.STAT_DAY AS STAT_TP,
       Y.ATRD_NM, Y.DRCT_CD_NM, Y.DRCT_NM,
       X.*
  FROM (SELECT /*+ INDEX(A PK_TAS_IFSC_SPED_HH) */
               A.STAT_DAY, B.ATRD_ID, 
               ROUND(AVG(H00), 0) AS H00, 
               ROUND(AVG(H01), 0) AS H01, 
               ROUND(AVG(H02), 0) AS H02, 
               ROUND(AVG(H03), 0) AS H03, 
               ROUND(AVG(H04), 0) AS H04, 
               ROUND(AVG(H05), 0) AS H05, 
               ROUND(AVG(H06), 0) AS H06, 
               ROUND(AVG(H07), 0) AS H07, 
               ROUND(AVG(H08), 0) AS H08, 
               ROUND(AVG(H09), 0) AS H09, 
               ROUND(AVG(H10), 0) AS H10, 
               ROUND(AVG(H11), 0) AS H11, 
               ROUND(AVG(H12), 0) AS H12, 
               ROUND(AVG(H13), 0) AS H13, 
               ROUND(AVG(H14), 0) AS H14, 
               ROUND(AVG(H15), 0) AS H15, 
               ROUND(AVG(H16), 0) AS H16, 
               ROUND(AVG(H17), 0) AS H17, 
               ROUND(AVG(H18), 0) AS H18, 
               ROUND(AVG(H19), 0) AS H19, 
               ROUND(AVG(H20), 0) AS H20, 
               ROUND(AVG(H21), 0) AS H21, 
               ROUND(AVG(H22), 0) AS H22, 
               ROUND(AVG(H23), 0) AS H23,
               ROUND(AVG(SPD), 0) AS SPD
          FROM TB_TAS_IFSC_SPED_HH A,
               MV_ATRD_IFSC        B
         WHERE A.STAT_DAY BETWEEN '20190501' AND '20190631'
           AND A.IFSC_ID = B.IFSC_ID
           --AND B.ATRD_NM IN ('')
           --AND B.DRCT_CD IN ('')
           --AND A.DAY_TYPE_CD IN ()
         GROUP BY A.STAT_DAY, B.ATRD_ID, B.DRCT_CD
       ) X,
       MV_ATRD Y
 WHERE 1=1
   AND Y.ATRD_ID = X.ATRD_ID
   --AND ATRD_NM IN ('')
   --AND DRCT_CD IN ('')
 ORDER BY X.STAT_DAY, Y.ATRD_NM

   
