-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.session2.sql
26 lines (26 loc) · 1.01 KB
/
local.session2.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
EXPLAIN SELECT *
FROM (
SELECT COUNT(id) as count,
DATE_TRUNC('day', created_at) AS DATE
FROM users u
WHERE DATE_TRUNC('day', created_at) BETWEEN TO_DATE('01-07-2021', 'DD-MM-YYYY') AND TO_DATE('01-08-2021', 'DD-MM-YYYY')
GROUP BY date
UNION
(
SELECT *
FROM (
SELECT 0 AS count,
GENERATE_SERIES(
TO_DATE('01-07-2021', 'DD-MM-YYYY'),
TO_DATE('01-08-2021', 'DD-MM-YYYY'),
interval '1 day'
) AS date
) as c
WHERE c.date NOT IN(
SELECT DATE_TRUNC('day', created_at) AS DATE
FROM users u
WHERE DATE_TRUNC('day', created_at) BETWEEN TO_DATE('01-07-2021', 'DD-MM-YYYY') AND TO_DATE('01-08-2021', 'DD-MM-YYYY')
GROUP BY date
)
)
) AS final_report ORDER BY final_report.date;