SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table website_user ( phone text, created_at date ); create table bot_user ( phone text, discr text not null, created_at date ); insert into website_user (phone, created_at) values ('793838371', '01-02-2019'::date); insert into website_user (phone, created_at) values (null, '01-02-2018'::date); insert into website_user (phone, created_at) values ('723123213123', '01-02-2022'::date); insert into bot_user (phone, discr, created_at) values ('793838371', 'viber', '01-02-2016'::date); insert into bot_user (phone, discr, created_at) values ('71111', 'whatsapp', '01-02-2017'::date); insert into bot_user (phone, discr, created_at) values (null, 'viber', '01-02-2020'::date); /* Выбираю вообще все телефоны из обоих таблиц, чтобы иметь полное представление о пользователях из любых источников */ with phones as ( select wu.phone, created_at, null as discr, true as is_website from website_user wu where wu.phone is not null union select bu.phone, created_at, array_agg(discr), false from bot_user bu where bu.phone is not null group by bu.phone, bu.created_at ) SELECT * FROM phones;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear