SELECT A.sy_menu_seq, A.menu_l_seq, A.menu_m_seq, A.menu_s_seq, A.menu_nm, A.menu_url,A.menu_depth, A.menu_link_yn, A.menu_prog_yn, A.sort
  FROM (
    SELECT A1.sy_menu_seq, A1.menu_l_seq, A1.menu_m_seq, A1.menu_s_seq, A1.menu_nm, A1.menu_url,A1.menu_depth, A1.menu_link_yn, A1.menu_prog_yn, A1.sort
      FROM (
        SELECT (A.menu_depth*100000000000) + (B.sort_idx * 100000000) sort
             , A.*
          FROM SY_MENU A
         INNER JOIN SY_MENU_MATCH_COMP B ON A.sy_menu_seq = B.sy_menu_seq AND B.ba_comp_seq = :login_comp_seq
         WHERE A.menu_depth = 1
           AND A.use_yn = 'Y'
           AND A.posi_cd = 'BAPOSB001'
         ORDER BY sort
      ) A1
     UNION
    SELECT A2.sy_menu_seq, A2.menu_l_seq, A2.menu_m_seq, A2.menu_s_seq, A2.menu_nm, A2.menu_url,A2.menu_depth, A2.menu_link_yn, A2.menu_prog_yn, A2.sort
      FROM (
          SELECT (A1.menu_depth*100000000000) + (B1.sort_idx * 100000000)
                +(A.menu_depth*10000000) + (B.sort_idx * 10000) sort
               , A.*
            FROM SY_MENU A
           INNER JOIN SY_MENU_MATCH_COMP B ON A.sy_menu_seq = B.sy_menu_seq AND B.ba_comp_seq = :login_comp_seq
           INNER JOIN SY_MENU A1 ON A1.sy_menu_seq = A.menu_l_seq AND A1.menu_depth = 1
           INNER JOIN SY_MENU_MATCH_COMP B1 ON A1.sy_menu_seq = B1.sy_menu_seq AND B1.ba_comp_seq = :login_comp_seq
           WHERE A.menu_depth = 2
             AND A.use_yn = 'Y'
             AND A.posi_cd = 'BAPOSB001'
           ORDER BY sort
      ) A2
     UNION
    SELECT A3.sy_menu_seq, A3.menu_l_seq, A3.menu_m_seq, A3.menu_s_seq, A3.menu_nm, A3.menu_url,A3.menu_depth, A3.menu_link_yn, A3.menu_prog_yn, A3.sort
      FROM (
          SELECT (A1.menu_depth*100000000000) + (B1.sort_idx * 100000000)
                +(A2.menu_depth*10000000) + (B2.sort_idx * 10000)
                +(A.menu_depth*1000) + (B.sort_idx * 1) sort
               , A.*
            FROM SY_MENU A
           INNER JOIN SY_MENU_MATCH_COMP B ON A.sy_menu_seq = B.sy_menu_seq AND B.ba_comp_seq = :login_comp_seq
           INNER JOIN SY_MENU A2 ON A2.sy_menu_seq = A.menu_m_seq AND A2.menu_depth = 2
           INNER JOIN SY_MENU_MATCH_COMP B2 ON A2.sy_menu_seq = B2.sy_menu_seq AND B2.ba_comp_seq = :login_comp_seq
           INNER JOIN SY_MENU A1 ON A1.sy_menu_seq = A.menu_l_seq AND A1.menu_depth = 1
           INNER JOIN SY_MENU_MATCH_COMP B1 ON A1.sy_menu_seq = B1.sy_menu_seq AND B1.ba_comp_seq = :login_comp_seq
           WHERE A.menu_depth = 3
             AND A.use_yn = 'Y'
             AND A.posi_cd = 'BAPOSB001'
           ORDER BY sort
      ) A3
  ) A
 ORDER BY sort