如果[2015]
和[2016]
为NULL,我想设置条件然后隐藏行,
但我不能把它拉下来。
如果billname
没有数据,我对它没兴趣。
SELECT
IssuedByUserGroup,
BILLNAME,
SUM([2016]) AS [2016],
SUM([2015])AS [2015]
FROM Sum_Orders
PIVOT
(
SUM(Sum_SellPrice)
FOR OrderperiodYear IN ([2016],[2015])
) AS pvt
WHERE ( (MONTH(OrderDate) = MONTH(GETDATE())
AND day(OrderDate) <= DAY(GETDATE())) OR MONTH(OrderDate) < MONTH(GETDATE()))
--This part above is just for getting the data since january 1 to sep 23(to the date)
AND OrderStatus in ('Complete','invoiced')
AND OrderPrefix IN ('LAX6')
GROUP BY BILLNAME,IssuedByUserGroup
ORDER BY IssuedByUserGroup desc
按预期返回以下内容:
谢谢!
答案 0 :(得分:2)
答案 1 :(得分:0)
您应该能够在PIVOT下面使用WHERE子句,如下所示:
WHERE [2015] IS NOT NULL