Answer the question
In order to leave comments, you need to log in
Postgres sum over different intervals?
Is it possible to implement the following - in one request to receive the amount for both the current day and the current month?
select
sum(value::real) as sum
FROM
analiz_data
--and CURRENT_DATE =f_timestamp::date
--and to_char(current_timestamp, 'YYYY-MM') = to_char(f_timestamp, 'YYYY-MM')
Answer the question
In order to leave comments, you need to log in
A bit of computational load:
select
sum(value) as month_sum,
sum(case when CURRENT_DATE =f_timestamp::date then value else 0 end) as today_sum
from ... where за этот месяц
you can, use over
UPD , corrected the request, it's more correct
SELECT
d.*,
sum(d.day_sum) OVER (PARTITION BY date_trunc('month', d.f_timestamp)) as month_sum
FROM (
SELECT
f_timestamp::date,
sum(value::real) as day_sum
FROM analiz_data
GROUP BY f_timestamp::date
) d
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question