I'm attempting to run a query, it yields the correct data, but I don't want it to look like that.
SELECT SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.06' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'TAX EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.06' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'NOT EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.065' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'TAX EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.065' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'NOT EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.07' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'TAX EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.07' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'NOT EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.075' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'TAX EXEMPT'
SUM(CASE WHEN TAX_TABLE.TAXVALUE = '0.075' THEN SALES_TABLE.TOTALSALE ELSE 0.0 END) AS 'NOT EXEMPT'
FROM ((ORDER_TB INNER JOIN SALES_TABLE ON ORDER_TB.RECID = SALES_TABLE.SALESID)
INNER JOIN TAX_TABLE ON ORDER_TB.SHIPZIPCODE = TAX_TABLE.ZCODE))
WHERE(((ORDER_TB.STATENAME) = 'FL')
AND ((ORDER_TB.SHIPDATE) BETWEEN 'MM/DD/YEAR' AND 'MM/DD/YEAR'))
If I run the query my results come out like this
|TAX EXEMPT|NOT EXEMPT|TAX EXEMPT|NOT EXEMPT|TAX EXEMPT|NOT EXEMPT|TAX EXEMPT|NOT EXEMPT|
|XXXXX.XX |XXX.XX |XXXXX.XX |XXX.XX |XXXXX.XX |XXXX.XX |XXX.XX |XX.XX |
I would like to show the results Like this
|TAX EXEMPT|NOT EXEMPT|
|XXXXX.XX |XXX.XX |
|XXXXX.XX |XXX.XX |
|XXXXX.XX |XXXX.XX |
|XXX.XX |XX.XX |
I tried to do a group by and include TAX_TABLE.TAXVALUE in my SELECT
GROUP BY TAX_TABLE.TAXVALUE
But when I do that It will just add 0.00 to the value corresponding to my CASE in my Query making the results much larger with unwanted Zeros. Is there somewhere in my CASES Which should be changed or would an UNPIVOT Be more Ideal?
答案 0 :(得分:0)
我想知道如何做到这一点归功于@Allan。 S汉森。我是新手,我不太确定你可以在CASE中添加多个WHEN,并且只能按需要产生两列。谢谢你的帮助。