I would like to count all the entries between 2 dates (the last week until today included) and if there are none, select 0. Currently it prints like this :
+-------+------------+
| items | SellDate |
+-------+------------+
| 1 | 2017-01-01 |
+-------+------------+
| 3 | 2017-01-02 |
+-------+------------+
| 1 | 2017-01-03 |
+-------+------------+
| 5 | 2017-01-06 |
+-------+------------+
However, I need something that print like this:
+-------+------------+
| items | SellDate |
+-------+------------+
| 1 | 2017-01-01 |
+-------+------------+
| 3 | 2017-01-02 |
+-------+------------+
| 1 | 2017-01-03 |
+-------+------------+
| 0 | 2017-01-04 |
+-------+------------+
| 0 | 2017-01-05 |
+-------+------------+
| 5 | 2017-01-06 |
+-------+------------+
| 0 | 2017-01-07 |
+-------+------------+
My query look like this:
SELECT
COUNT(Item.id) AS Items,
DATE(Item.sold_at) AS SellDate
FROM Item
WHERE Item.sold_at IS NOT NULL AND Item.sold_at BETWEEN DATE(DATETIME('now', 'localtime', '-6 days')) AND DATE(DATETIME('now', 'localtime', '+1 day'))
GROUP BY SellDate
What I am doing wrong?