SELECT A.AP_MTCH_EXCP_GRP , A.DESCR50 , B.OPRID FROM PS_AP_MTCH_EX_GRP A , PS_AP_MTCH_GRP_USR B ,PS_AP_MEC_OPCNT_VW C WHERE A.EFF_STATUS = 'A' AND A.AP_MTCH_EXCP_GRP = B.AP_MTCH_EXCP_GRP AND B.OPRID = C.OPRID AND C.COUNT1 < 2 AND C.TYPE = 'U' AND ((SELECT COUNT(*) FROM PS_AP_MEC_OPCNT_VW D WHERE D.OPRID = B.OPRID) < 2) UNION SELECT A.AP_MTCH_EXCP_GRP , A.DESCR50 , C.ROLEUSER FROM PS_AP_MTCH_EX_GRP A , PS_AP_MTCH_GRP_ROL B , PSROLEUSER C ,PS_AP_MEC_OPCNT_VW E WHERE A.EFF_STATUS = 'A' AND A.AP_MTCH_EXCP_GRP = B.AP_MTCH_EXCP_GRP AND B.ROLENAME = C.ROLENAME AND NOT EXISTS ( SELECT 'X' FROM PS_AP_MTCH_GRPEXCL D WHERE D.AP_MTCH_EXCP_GRP = B.AP_MTCH_EXCP_GRP AND C.ROLEUSER = D.OPRID AND D.ROLENAME = B.ROLENAME) AND C.ROLEUSER = E.OPRID AND E.COUNT1 < 2 AND E.TYPE = 'R' AND ((SELECT COUNT(*) FROM PS_AP_MEC_OPCNT_VW F WHERE F.OPRID = C.ROLEUSER) < 2)
|