У меня три запроса вроде этого:
select count(*) as customers, created_at::date as date from table1 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC
select count(*) as customers, created_at::date as date from table2 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC
select count(*) as customers, created_at::date as date from table3 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC
Мне нужно получить два столбца: дату и общую сумму customers
из трех таблиц. Я попытался с подзапросом, но не был уверен, как позиционировать GROUP BY
без ошибок. Я пробовал что-то вроде этого:
select ((select count(*) as customers, created_at::date as date from table1 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC)+(select count(*) as customers, created_at::date as date from table2 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC)+(select count(*) as customers, created_at::date as date from table3 where subscription_ends_at IS NOT NULL group by created_at::date order by created_at::date ASC)) AS SumCount