0
我有一個表,我需要從一切與此規則選擇:Postgres的內部查詢性能
id = 4524522000143 and validPoint = true
and date > (max(date)- interval '12 month')
-- the max date, is the max date for this id
解釋規則:我必須讓所有的寄存器和計數他們,他們必須至少1年從最新的註冊表中刪除舊的。
這是我的實際查詢:
WITH points as (
select 1 as ct from base_faturamento_mensal
where id = 4524522000143 and validPoint = true
group by id,date
having date > (max(date)- interval '12 month')
) select sum(ct) from points
是否有這種更有效的方法?