Вы можете легко поместить результаты в отдельные столбцы:
select sum(case when createddate >= CURRENT_DATE - 1 then 1 else 0 end) as yesterday,
sum(case when createddate >= CURRENT_DATE - 7 then 1 else 0 end) as last_week,
sum(case when createddate >= CURRENT_DATE - 30 then 1 else 0 end) as last_month,
sum(case when createddate >= CURRENT_DATE - 90 then 1 else 0 end) as last_90days,
count(*) as total
from my_table;
Если вы хотите разделить строки, вы можете отключить вышеперечисленное или просто использовать union all
:
select 'Yesterday' as which, count(*) from my_table where createddate >= CURRENT_DATE - 1
union all
select 'Last week', count(*) from my_table where createddate >= CURRENT_DATE - 7
union all
select 'Last month', count(*) from my_table where createddate >= CURRENT_DATE - 30
union all
select 'Last 90 days', count(*) from my_table where createddate >= CURRENT_DATE - 90
union all
select 'Total', count(*) from my_table;