Re: [GENERAL] count records in two different table joined by
От | Patrick B |
---|---|
Тема | Re: [GENERAL] count records in two different table joined by |
Дата | |
Msg-id | CAJNY3iudYAFTG-bS33WBH9i0nQLpCN-PkXvbUrAJ2Jv03=4Z9g@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: [GENERAL] count records in two different table joined by (Thomas Markus <t.markus@proventis.net>) |
Ответы |
Re: [GENERAL] count records in two different table joined by
|
Список | pgsql-general |
2017-07-07 22:32 GMT+12:00 Thomas Markus <t.markus@proventis.net>:
Hi,Am 07.07.17 um 12:16 schrieb Patrick B:one possibility is:Hi guys!I've got 2 tables, and I need to get some data between them.test1:test2:WITH account_status AS (selectCASEWHEN regdate = 1 THEN 'yes'WHEN regdate = 2 THEN 'no'from test1end as status_a)select status_a from account_status group by status_aWITH user_status AS (selectCASEWHEN regdate = 1 THEN 'yes'WHEN regdate = 2 THEN 'no'from test1join test2 as t2 on t2.test1_id = t1.idend as status_a)select status_a from user_status group by status_aIt 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
select distinct
case
when regdate = 1 THEN 'yes'
when regdate = 2 THEN 'no'
end as status_a
, t2.id is null as test2exists
from test1 t1 left join test2 t2 on t2.test1_id = t1.id
hth
Thomas
hmmm... not really
I want this to work:
I want this to work:
WITH account_status AS (selectCASEWHEN regdate = 1 THEN 'yes'WHEN regdate = 2 THEN 'no'end as status_a,count(t2.id) as t2_countfrom test1 as t1join test2 as t2 on t2.test1_id = t1.idend as status_a)selectstatus_a,t2_count,count(*)from account_status group by status_a, t2_count
В списке pgsql-general по дате отправления: