我有以下一组数据:
ID | CREATED | USER
--------------------------
1 | 2012-01-14 | XYZ
2 | 2012-03-14 | XYZ
3 | 2012-03-15 | XYZ
4 | 2012-03-24 | ABC
5 | 2012-04-10 | XYZ
6 | 2012-04-11 | ABC
我需要一份报告,显示给定用户的 COUNT,但在没有记录的月份中显示 0。
MTH | COUNT
-------------
JAN | 1
FEB | 0
MAR | 2
APR | 1
我设法让它工作,但没有 0 几个月没有记录。到目前为止,我有这个抛出错误的语法..
SELECT Month(CREATED), COUNT(SELECT * FROM SEARCHES WHERE USER = 'XYZ')
FROM SEARCHES
GROUP BY Month(CREATED)