我有一个查询,按会计月份按客户提取销售额。但是,我有一些客户在给定月份没有购买。对于这些情况,我希望 MonthNum 字段的 SalesDlr 值为 0,但 MonthNum 值仍需要是实际的月份数。目前,我在下面的查询中没有得到 MonthNum 值:
SELECT
a.Customer,
a.CustomerName,
a.MonthNum,
a.FiscalYear,
a.SalesDlr
FROM
(SELECT
sd.SBCUST AS Customer,
sd.RMNAME AS CustomerName,
fc.FiscalMonthNum AS MonthNum,
fc.FiscalYear,
SUM(sd.SBEPRC) AS SalesDlr
FROM
dbo.SalesData sd
LEFT OUTER JOIN dbo.FiscalCalendar fc ON fc.FiscalDate = sd.SBINDT
WHERE
sd.SBTYPE = 'O'
AND
sd.SBINDT > '2012-12-31'
AND
sd.SBCLS NOT IN ('1500')
GROUP BY
sd.SBCUST,
sd.RMNAME,
fc.FiscalMonthNum,
fc.FiscalYear
)a
GROUP BY
a.Customer,
a.CustomerName,
a.MonthNum,
a.FiscalYear,
a.SalesDlr
ORDER BY
a.Customer,
a.MonthNum,
a.FiscalYear
我该如何解决?