已经有同样的问题,但没有正确答案。
Alias names to with rollup in SQL queries?
我需要知道如何用total替换NULL。
以下是使用WITH ROLLUP的查询副本。
SELECT CASE
WHEN OCRD.Region = [Region Table].RegionID THEN [Region Table].description
ELSE 'Not Region'
END,
'$'
+ CONVERT(VARCHAR, Cast(Sum(INV1.LineTotal) AS MONEY), 1) AS Total
FROM OINV
INNER JOIN INV1
ON OINV.DocEntry = INV1.DocEntry
INNER JOIN OCRD
ON OINV.CardCode = OCRD.CardCode
LEFT JOIN [Region Table]
ON OCRD.Region = [Region Table].RegionID
WHERE OINV.DocDate BETWEEN Getdate() - 300 AND Getdate() + 300
AND Month(OINV.DocDate) = Month(Getdate())
GROUP BY CASE
WHEN OCRD.Region = [Region Table].RegionID THEN [Region Table].description
ELSE 'Not Region'
END WITH ROLLUP
这是输出:
France $34
Japan $117
USA $897
China $250
NULL $1,298
我希望看到'NULL'值替换为'Total':
France $34
Japan $117
USA $897
China $250
Total $1,298
我真的很感激任何输入。