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
是否有这种更有效的方法?