我想将这些选择的结果放在一个视图中。公共列是 RUNID,但是右表的结果并不总是存在。所以它应该返回空。我认为所有这些选择都可以组合成一个选择,将 RUNID 传递给不同标准的每个计数。
--COUNT OF S16 ELIGIBLE ACCOUNTS
SELECT PDDETAIL.RUNID, COUNT(*) AS "S16 ELIGIBLE ACCOUNTS"
FROM PDDETAIL
LEFT JOIN PDSTAGES ON (PDDETAIL.PDID = PDSTAGES.PDID AND PDDETAIL.CUST_ID = PDSTAGES.CUST_ID)
WHERE PDSTAGES.PDSTAGE = 'S16ELIGIBLE'
GROUP BY PDDETAIL.RUNID
ORDER BY PDDETAIL.RUNID ASC
;
--COUNT OF S16 MTO SUBMITTED
SELECT PDDETAIL.RUNID,COUNT(*) AS "S16 MTO SUBMITTED"
FROM PDDETAIL
LEFT JOIN PDSTAGES ON (PDDETAIL.PDID = PDSTAGES.PDID AND PDDETAIL.CUST_ID = PDSTAGES.CUST_ID)
WHERE PDSTAGES.PDSTAGE = 'S16MTOREFRESHSUBMITTED'
GROUP BY PDDETAIL.RUNID
ORDER BY PDDETAIL.RUNID ASC
;
--COUNT OF S16 MTO RETURN FAILED
SELECT PDDETAIL.RUNID,COUNT(*) AS "S16 MTO FAILED"
FROM PDDETAIL
LEFT JOIN PDSTAGES ON (PDDETAIL.PDID = PDSTAGES.PDID AND PDDETAIL.CUST_ID = PDSTAGES.CUST_ID)
WHERE PDSTAGES.PDSTAGE = 'S16MTORETURNFAILED'
GROUP BY PDDETAIL.RUNID
ORDER BY PDDETAIL.RUNID ASC
;