count records in two different table joined by

From: Patrick B <patrickbakerbr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: count records in two different table joined by
Date: 2017-07-07 10:16:04
Message-ID: CAJNY3iuOCEtBnNDVXyo3z8aRA76F2kSnMUFrG2=E7mQaoG6csQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi guys!

I've got 2 tables, and I need to get some data between them.

test1:

WITH account_status AS (
select
CASE
WHEN regdate = 1 THEN 'yes'
WHEN regdate = 2 THEN 'no'
from test1
end as status_a
)

select status_a from account_status group by status_a

test2:

WITH user_status AS (
select
CASE
WHEN regdate = 1 THEN 'yes'
WHEN regdate = 2 THEN 'no'
from test1
join test2 as t2 on t2.test1_id = t1.id
end as status_a
)

select status_a from user_status group by status_a

It works fine.. but I would like to get that data in one single query.. How
can I do that?

I'm using Postgres 9.3.

Thanks!
Patrick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Markus 2017-07-07 10:32:02 Re: count records in two different table joined by
Previous Message Osahon Oduware 2017-07-07 07:59:27 Re: Renaming Raster Table