Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
SELECT entity_id, trans_date , COALESCE(sum(daily_amount) OVER w, 0) AS trans_total , COALESCE(sum(daily_count) OVER w, 0) AS trans_count FROM ( SELECT entity_id , generate_series (min(trans_date)::timestamp , GREATEST(min(trans_date), max(trans_date) - 29)::timestamp , interval '1 day')::date AS trans_date FROM transactiondb GROUP BY 1 ) x LEFT JOIN ( SELECT entity_id, trans_date , sum(amount) AS daily_amount, count(*) AS daily_count FROM transactiondb GROUP BY 1, 2 ) t USING (entity_id, trans_date) WINDOW w AS (PARTITION BY entity_id ORDER BY trans_date ROWS BETWEEN CURRENT ROW AND 29 FOLLOWING);

Stuck with a problem? Got Error? Ask AI support!

Copy Clear