我面临一个查询问题。
我的查询是:-
SELECT MONTH(o.OrderDate) as MonthValue,
YEAR(o.OrderDate) as YearValue,
C.CustomerTypeID, Count(o.Total) as NoOfOrders
FROM Orders o
RIGHT JOIN Customers C on C.CustomerID = o.CustomerID
WHERE o.OrderDate >= CONVERT(DATETIME, '1/1/2013 00:00:00 AM')
AND o.OrderDate <= CONVERT(DATETIME, '12/31/2013 23:59:59 PM')
GROUP BY MONTH(o.OrderDate),
YEAR(o.OrderDate),
C.CustomerTypeID
ORDER BY MONTH(o.OrderDate),
YEAR(o.OrderDate),
C.CustomerTypeID
它给出的结果如下: -
MonthValue YearValue CustomerTypeID NoOfOrders
1 2013 1 10
1 2013 2 20
1 2013 3 45
2 2013 1 45
2 2013 2 45
3 2013 1 88
3 2013 2 56
3 2013 3 89
至于第 2 个月,客户类型 3 没有结果,因此它不会出现在结果中。
但我想将“0”显示为它的默认结果,如下所示:-
2 2013 3 0
提前致谢。