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     = SUBSTR(:p03, 1, 6)                                           
   AND A.DAY_TYPE_CD = :p04                                                         
   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) = :p05)
                      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)                  
