我有以下查询:
select
Pr.Name, PS.TotalSales, PS.Truesales
From
Product Pr
Left Join
(select ProdudtId, TotalSales = COUNT(Transaction.Id),
Truesales = COUNT(DISTINCT case when .Transaction.ExceptionCode = ' ' then Transaction.Id END)
from [Transaction]
WHERE
(ResponseTime < '2013/05/16 01:53:52' and RequestTime > '2013/05/11 01:53:52')
Group By
ProductId) PS on PS.ProductId = Pr.ProductId
我得到这样的结果:
Name TotalSales TrueSales
AB 3 2
CD NULL NULL
EF 1 1
我想得到这样的结果
Name TotalSales TrueSales
AB 3 2
CD 0 0
EF 1 1
我希望看到 0 代替 nulls 。谁能告诉我需要在查询中进行哪些更改?
两张表如下:
1 ) Product
ProuctId, Name
2) Sales
TransactionId, ReqTime, ResTime, ProductId(FK), ExceptionCode