I have a report (using Blazer, if you care) that displays data like this, of recently updated or created rows in the jobs
table:
5 Minutes | 1 Hour | 1 Day | Total
----------------------------------
0 0 367 30,989
The SQL looks something like this:
SELECT
(SELECT COUNT(*)
FROM public.jobs AS "Jobs"
WHERE "Jobs"."updated_at" BETWEEN NOW() - INTERVAL '5 minutes' AND NOW()
) as "5 Minutes",
(SELECT COUNT(*)
FROM public.jobs AS "Jobs"
WHERE "Jobs"."updated_at" BETWEEN NOW() - INTERVAL '1 Hours' AND NOW()
) as "1 Hour",
(SELECT COUNT(*)
FROM public.jobs AS "Jobs"
WHERE "Jobs"."updated_at" BETWEEN NOW() - INTERVAL '1 Day' AND NOW()
) as "1 Day",
(SELECT COUNT(*)
FROM public.jobs AS "Jobs"
) as "Total"
;
I want to add a second row, for jobs WHERE "Jobs"."active" IS TRUE
. How do I make this display another row?
I want the final result to be something like this:
Status | 5 Minutes | 1 Hour | 1 Day | Total
-------------------------------------------
* 0 0 367 30,989
Active 0 0 123 24,972
The labels are not the issue. The only thing that's not obvious is how to create a new row.
The simplest way is to UNION on another bunch of queries, that have this more restrictive where clause: