I've got two tables that I need a count on both of them.
table1: id
table2: cid (table1.id = table2.cid) -- Join can be done by this.
I already got two queries that I'm using, and wanna put them in one single query.
Query related to
table1
:
WITH c_status AS (
select
CASE
WHEN regdate = 1 THEN 'yes'
WHEN regdate = 2 THEN 'no'
from table1
end as status_1
)
select status_1, count(*) AS c_status_count from c_status group by status_1
OUTPUT:
yes 548
no 2269
Query related to table2
:
WITH u_status AS (
select
CASE
WHEN regdate = 1 THEN 'yes'
WHEN regdate = 2 THEN 'no'
from table2
end as status_2
)
select status_2, count(*) AS u_status_count from u_status group by status_2
OUTPUT:
yes 564256
no 31452345234
Question:
How can I put those two queries together? I want one single query reporting both counts.
UPDATE: Desired output:
u_status yes 548
u_status no 2269
c_status yes 564256
c_status no 31452345234
Asked by Patrick B.
(311 rep)
Jul 9, 2017, 09:51 PM
Last activity: Apr 14, 2024, 07:15 PM
Last activity: Apr 14, 2024, 07:15 PM