SELECT
MON.month,
A所有记录总数 = A.cnt,
B表的记录数 = B.cnt
FROM(
SELECT month = N'一月', months = 1 UNION ALL
SELECT month = N'二月', months = 2 UNION ALL
SELECT month = N'三月', months = 3 UNION ALL
SELECT month = N'四月', months = 4 UNION ALL
SELECT month = N'五月', months = 5 UNION ALL
SELECT month = N'六月', months = 6 UNION ALL
SELECT month = N'七月', months = 7 UNION ALL
SELECT month = N'八月', months = 8 UNION ALL
SELECT month = N'九月', months = 9 UNION ALL
SELECT month = N'十月', months = 10 UNION ALL
SELECT month = N'十一月', months = 11 UNION ALL
SELECT month = N'十二月', months = 12
)MON
LEFT JOIN(
SELECT
months = DATEPART(Month, datetime),
cnt = COUNT(*)
FROM A
GROUP BY DATEPART(Month, datetime)
)A
ON MON.months = A.months
LEFT JOIN(
SELECT
months = datemonth,
cnt = COUNT(*)
FROM B
GROUP BY datemonth
)B
ON MON.months = B.months