SQL: Subtracting 1 day from a timestamp date
Use the INTERVAL type to it. E.g: –yesterday SELECT NOW() – INTERVAL ‘1 DAY’; –Unrelated: PostgreSQL also supports some interesting shortcuts: SELECT ‘yesterday’::TIMESTAMP, ‘tomorrow’::TIMESTAMP, ‘allballs’::TIME AS aka_midnight; You can do the following then: SELECT org_id, count(accounts) AS COUNT, ((date_at) – INTERVAL ‘1 DAY’) AS dateat FROM sourcetable WHERE date_at <= now() – INTERVAL ‘130 DAYS’ … Read more