您好我在我的交易表中保留了我的购买和发行类型0和1。 现在我想用两列检索单行购买和发行的总和。我的问题:
SELECT (CASE WHEN TransType = 0 THEN SUM(Amount) END) PurchaseAmt,
(CASE WHEN TransType = 1 THEN SUM(Amount) END) IssueAmt
FROM TransMaster
WHERE TransType in (0,1)
GROUP BY TransType
以上查询返回以下行
PurchaseAmt IssueAmt
13600123.00 NULL
NULL 12952262.00][1]
但我的期望是单行如下
PurchaseAmt IssueAmt
13600123.00 12952262.00
有可能吗?
答案 0 :(得分:2)
试
SELECT Sum(CASE
WHEN transtype = 0 THEN amount else 0
END) PurchaseAmt,
Sum(CASE
WHEN transtype = 1 THEN amount else 0
END) IssueAmt
FROM transmaster
WHERE transtype IN ( 0, 1 )