Я делаю довольно длинный запрос, чтобы найти клиента с определенным условием в определенные даты, в данном случае '2019-6-20'
, запрос такой:
Вот мой код
select current_date() as date , count(customer_id) as cell13
from(
select customer_id, count(id) as total, string_agg(payment_state order by created_at desc limit 1) as cek
from(
select distinct(A.id), A.customer_id, extract(month from A.created_at) as months,extract(day from A.created_at) as days, extract(year from A.created_at) as years, payment_state, A.created_at, A.grandtotal_cents
from bl.orders as A
left join bl.blacklists as B
on A.customer_id = B.customer_id
where date(A.created_at) >= date_sub(date('2019-6-20') , interval 60 day) and grandtotal_cents > 0 and B.customer_id is null
)
group by customer_id
having cek = "unpaid")
Вот результат
Row date cell13
1 2019-06-21 696
Теперь мне нужно запросить это для нескольких дат в определенном диапазоне дат, например от 2019-03-23
до 2019-06-21
.Как предположить, что я делаю это, поэтому вывод будет выглядеть как
Row date cell13
1 2019-06-21 696
...
90 2019-03-23 ...