ttiiffffnnhh22000022
Technical User
I am trying to display all JPNUMS and it's count of labor and tasks. They query below is only showing JPNUMS where there is labor and tasks however I want to show the JPNUMS where labor and/or tasks are also zero.
SELECT JP.JPNUM, JP.STATUS,
JPT.TASKCOUNT,
JPL.CRAFTCOUNT
FROM
(SELECT JPNUM, STATUS, COUNT(*) JPCOUNT
FROM MISSO.JOBPLAN JP
WHERE PLUSCREVNUM = (SELECT MAX(PLUSCREVNUM) FROM MISSO.JOBPLAN WHERE JPNUM = JP.JPNUM)
AND STATUS IN ('DRAFT','ACTIVE','PNDREV') and ORGID='GOM'
GROUP BY JPNUM, STATUS
) JP,
(SELECT JPNUM,COUNT(*) TASKCOUNT
FROM MISSO.JOBTASK JT
WHERE PLUSCJPREVNUM =(SELECT MAX(PLUSCJPREVNUM) FROM MISSO.JOBTASK WHERE JPNUM = JT.JPNUM)
GROUP BY JPNUM
) JPT,
(SELECT JPNUM,COUNT(*) CRAFTCOUNT
FROM MISSO.JOBLABOR JL
WHERE PLUSCJPREVNUM =(SELECT MAX(PLUSCJPREVNUM) FROM MISSO.JOBTASK WHERE JPNUM = JL.JPNUM)
GROUP BY JPNUM
) JPL
where JP.JPNUM = JPL.JPNUM
AND JPL.JPNUM = JPT.JPNUM
SELECT JP.JPNUM, JP.STATUS,
JPT.TASKCOUNT,
JPL.CRAFTCOUNT
FROM
(SELECT JPNUM, STATUS, COUNT(*) JPCOUNT
FROM MISSO.JOBPLAN JP
WHERE PLUSCREVNUM = (SELECT MAX(PLUSCREVNUM) FROM MISSO.JOBPLAN WHERE JPNUM = JP.JPNUM)
AND STATUS IN ('DRAFT','ACTIVE','PNDREV') and ORGID='GOM'
GROUP BY JPNUM, STATUS
) JP,
(SELECT JPNUM,COUNT(*) TASKCOUNT
FROM MISSO.JOBTASK JT
WHERE PLUSCJPREVNUM =(SELECT MAX(PLUSCJPREVNUM) FROM MISSO.JOBTASK WHERE JPNUM = JT.JPNUM)
GROUP BY JPNUM
) JPT,
(SELECT JPNUM,COUNT(*) CRAFTCOUNT
FROM MISSO.JOBLABOR JL
WHERE PLUSCJPREVNUM =(SELECT MAX(PLUSCJPREVNUM) FROM MISSO.JOBTASK WHERE JPNUM = JL.JPNUM)
GROUP BY JPNUM
) JPL
where JP.JPNUM = JPL.JPNUM
AND JPL.JPNUM = JPT.JPNUM