我需要显示每个部分的数据,我的查询工作......差不多。这是我的语法
Select * From
(
Select item As [item], Count(sold) As [Count], StoreName
From saleinfo
Group By item, storename
) first
pivot
(
Count([Count])
for item in ([brake pads], [rotors],[shoes],[drums]
) piv
现在我遇到的问题是,如果他们是0的计数返回,则结果中省略了该项目。意思是如果出售了0个刹车片,那么我的结果集中没有显示刹车片。即使返回的计数为0,我如何才能显示该项?
答案 0 :(得分:0)
您可以使用ISNULL或COALESCE 将 NULL转换为0
:
Select isnull([brake pads], 0) as [brake pads], isnull([rotors], 0) as [rotors], isnull([shoes], 0) as [shoes], isnull([drums], 0) as [drums]
From
(
...