Running Total Of Daily Sales
How do I get the running total of sales per day in PostgreSQL?
sql
SELECT created_at::date AS sale_date, SUM(price) AS daily_total, SUM(SUM(price)) OVER (ORDER BY created_at::date) AS running_total FROM orders GROUP BY created_at::date;
This query calculates the daily sum of the "price" column from the "orders" table and uses the SUM() window function to compute a cumulative running total ordered by the date.
PromptDB can make mistakes. Please double-check responses.