I am trying to write a SQL Server query which should return the zero count record as well. I know that aggregate functions ignore NULL values.
SELECT
DAY(job_start_date) as day,
count(app_id) as execution
FROM job_application_details
WHERE
job_start_date >= DATEADD(day, -30, GETDATE())
and job_start_date <= getdate()
and app_id = 51
group by DAY(job_start_date);
Above query returns the result like below:
| day | execution
-------+------+--------------
1 | 9 | 1
2 | 12 | 1
3 | 15 | 1
4 | 30 | 1
Since for the other days, there are no records present in the table so it doesn't return it with 0 count. So, I want to write a query which returns the records of 30 days including the ones having 0 executions.
Please help to resolve this. Thanks in advance.