我當前的查詢拉這樣的事情:即使在沒有行返回的情況下如何拉取摘要數據?
╔════════════════════════════════════════╗
║ A Monthly 123 123 123 123 123 123 ║
║ B Quarterly 123 123 123 123 123 123 ║
║ C SemiAnnual 123 123 123 123 123 123 ║
║ D Annual 123 123 123 123 123 123 ║
╚════════════════════════════════════════╝
的問題出現時,我沒有得到一個特定模式的行返回。當發生這種情況時,它只會下降模式。
我想讓它顯示:
╔════════════════════════════════════════╗
║ A Monthly 123 123 123 123 123 123 ║
║ B Quarterly 0 0 0 0 0 0 ║
║ C SemiAnnual 123 123 123 123 123 123 ║
║ D Annual 123 123 123 123 123 123 ║
╚════════════════════════════════════════╝
我知道有一種方法可以做到這一點。只是畫空白。就像分別拉模式然後拉和數?
這裏是我當前的查詢:
SELECT MODE,
SUM(POLCT) AS POLCT,
SUM(RDRCNT) AS RDRCNT,
SUM(INCCNT) AS INCCNT,
SUM(INCINS) AS INCINS,
SUM(INS_AMOUNT) AS INS_AMOUNT,
SUM (PREM) AS PREM
FROM (SELECT CASE
WHEN MODE = '12' THEN 'D Annual'
WHEN MODE = '03' THEN 'B Quarterly'
WHEN MODE = '06' THEN 'C SemiAnnual'
WHEN MODE = '01' THEN 'A Monthly'
ELSE ' '
END AS MODE,
POLICY_COUNT * NEGATIVE AS POLCT,
RIDER_COUNT * NEGATIVE AS RDRCNT,
INCNT * NEGATIVE AS INCCNT,
INS_AMOUNT * NEGATIVE * INCNT AS INCINS,
INS_AMOUNT * NEGATIVE AS INS_AMOUNT,
PRSC * NEGATIVE AS PREM
FROM DIST_OF_ISSUES AS a
LEFT OUTER JOIN DIST_OF_ISSUES_PLANS AS b
ON a.PLANID = b.PLANID
LEFT OUTER JOIN DIST_OF_ISSUES_TYPE_ORDER AS c
ON b.TYPE = c.TYPE
WHERE SUBSTRING(a.PLANID, 1, 4) NOT IN (
'1020', '2599', '1600', '1601',
'2597', '2598')
AND (a.MONTH < 4
AND a.MONTH > 0)
AND a.YEAR = 2014) AS A
GROUP BY MODE
ORDER BY MODE
這似乎像什麼,我攻向但是當我試圖用這個代碼,它不工作。看到我的答案是什麼工作。你的路線雖然看起來比較清潔 – user3805697