I have the below query
SELECT DATEPART(YEAR, Date_Reported) AS 'Year',
DATEPART(MONTH, Date_Reported) AS 'Month',
DATEPART(DAY, Date_Reported) AS 'Day',
COUNT(*) AS 'Transactions'
FROM TX
WHERE Date_Reported >= DATEADD(day,-7, GETDATE())
GROUP BY DATEPART(DAY, Date_Reported),
DATEPART(MONTH, Date_Reported),
DATEPART(YEAR, Date_Reported)
ORDER BY 'Year',
'Month',
'Day'
What it gives me is the last 7 days of transactions, but when a days transaction is 0 it does not show a row. What I would like is for the no rows to be displayed as a 0 value under the transaction column like below:
YEAR | MONTH | DAY | TRANSACTIONS
2018 | 9 | 4 | 2
2018 | 9 | 5 | 2
2018 | 9 | 6 | 0
2018 | 9 | 7 | 5
2018 | 9 | 8 | 2
2018 | 9 | 9 | 0
2018 | 9 | 10 | 0
Any ideas?