1

これらの選択の結果を1つのビューにまとめたいと思います。共通の列はRUNIDですが、右側のテーブルの結果が常に表示されるとは限りません。したがって、空に戻るはずです。これらすべての選択を1つの選択に組み合わせて、さまざまな基準の各カウントに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
;
4

1 に答える 1

3
SELECT    
 PDDETAIL.RUNID,
 COUNT(CASE WHEN PDSTAGES.PDSTAGE = 'S16ELIGIBLE' THEN 1 END) AS "S16 ELIGIBLE ACCOUNTS",
 COUNT(CASE WHEN PDSTAGES.PDSTAGE = 'S16MTOREFRESHSUBMITTED' THEN 1 END) AS "S16 MTO SUBMITTED",
 COUNT(CASE WHEN PDSTAGES.PDSTAGE = 'S16MTORETURNFAILED' THEN 1 END) AS "S16 MTO FAILED"
FROM      PDDETAIL
LEFT JOIN PDSTAGES ON (PDDETAIL.PDID = PDSTAGES.PDID AND PDDETAIL.CUST_ID = PDSTAGES.CUST_ID)
GROUP BY  PDDETAIL.RUNID
ORDER BY  PDDETAIL.RUNID ASC;
于 2012-09-24T15:49:45.897 に答える