Similar to this question - Postgres - how to return rows with 0 count for missing data?
I have a table to tack number of users used my service per day. I record it by timestamps and user ID. Current query -
SELECT DATE_TRUNC('day', recorded_at), COUNT(log_id) AS daily_count FROM uses_tracker
WHERE log_id = 15183 AND recorded_at >= now() - INTERVAL '30 DAYS' GROUP BY 1
It returns me the data in this format -
date_trunc daily_count
2021-04-01 00:00:00.000000 2
2021-04-06 00:00:00.000000 1
Expected Format -
date_trunc daily_count
2021-04-01 00:00:00.000000 2
2021-04-02 00:00:00.000000 0
2021-04-03 00:00:00.000000 0
2021-04-04 00:00:00.000000 0
2021-04-05 00:00:00.000000 0
2021-04-06 00:00:00.000000 1
the data which i am getting currently is because other timestamps are not inserted in DB. How to add the missing one's while querying the data?