過去 1 年間に提出されたレポートの数を日付順に並べたクエリを作成しています。私はphpで現在の年と月を取得します:
$year = date('Y') - 1;
$month = date('m');
次のクエリを実行します: SQL:
SELECT month(date_lm) AS `month` ,
count(*) AS `count`
FROM `reports`
WHERE (status = 'submitted')
AND (date_lm > 2012-08)
GROUP BY month(date_lm)
ORDER BY month(date_lm) ASC
そして、昨年は1件しか提出されていないため、結果は1件しかありません...
| month | count |
| 7 | 1 |
しかし、結果セットに次のように表示したいと思います。
| month | count |
| 9 | 0 |
| 10 | 0 |
| 11 | 0 |
| 12 | 0 |
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 0 |
| 5 | 0 |
| 6 | 0 |
| 7 | 1 |
| 8 | 0 |
それは可能ですか?