1. 程式人生 > >三表查詢,三會一課

三表查詢,三會一課

SELECT T.LRRQ,
                         T.UUID,
                         T.YTMC,
                         T.HYSJ,
                         T.HYDD,
                         T.DEPT_ID,
                         a.CJNUM,
                         b.QXNUM
                    from NBGL_DJGL_SHYK T,
                         (select uuid, sum(num) cjnum
                            from (select k.uuid,
                                         (case
                                           when y.RYLX_DM = '01' then
                                            1
                                           else
                                            0
                                         end) num
                                    from NBGL_DJGL_SHYK k, DJGL_SHYK_CJRY y
                                   where k.uuid = y.Zjuuid(+))
                           group by uuid) A,
                         (select uuid, sum(num) qxnum
                            from (select k.uuid,
                                         (case
                                           when y.RYLX_DM = '02' then
                                            1
                                           else
                                            0
                                         end) num
                                    from NBGL_DJGL_SHYK k, DJGL_SHYK_CJRY y
                                   where k.uuid = y.Zjuuid(+))
                           group by uuid) B
                   where t.uuid = a.uuid(+)
                     and t.uuid = B.uuid(+)