- How do I calculate a running total or cumulative sum in SQL?
- Ask in plain English — 'running total of revenue by day.' nlqdb compiles the window function (`SUM(amount) OVER (ORDER BY day)`), runs it in Postgres, and returns the accumulating rows plus the SQL it ran. You get the cumulative curve without hand-writing the `OVER (ORDER BY ...)` clause or debugging the frame. The honest limit: you have to name the order it accumulates in.
- What's the difference between SUM with GROUP BY and a running total?
- A plain `SUM() ... GROUP BY` collapses each group to one total row — you lose the per-row detail. A running total keeps every row and shows the sum accumulated up to that row, using a window function: `SUM(amount) OVER (ORDER BY day)`. nlqdb picks the window form when you ask for a 'running' or 'cumulative' total, and shows the compiled SQL so you can confirm which one you got.
- Can I compute a running total on a Postgres database I already run?
- Yes — connect it with the signed-in BYO connect verb (`nlq db connect`; see /solve/query-existing-postgres-in-natural-language) and ask for the cumulative curve in place, no ETL into a separate store. The honest limits: BYO connect is signed-in only (not the public embed), and nlqdb returns the running total with a read-only query — it doesn't persist a materialized cumulative column for you.
- Can nlqdb do a moving average or 7-day rolling sum too?
- Yes — those are the same window-function family with a frame clause: `SUM(...) OVER (ORDER BY day ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)` for a 7-day rolling sum. Ask for a 'moving' or 'rolling' total and nlqdb compiles the frame, then shows the SQL so you can confirm the window width. The honest limit: name the window size and the order it slides over.
- What does a running total (cumulative sum) actually mean?
- A running total is a column summed in order, so each row shows the total of everything up to and including it — day 1 alone, then day 1 + 2, then day 1 + 2 + 3, and so on. 'Cumulative sum' and 'running total' name the same thing. It differs from a grand total (one final number) because it keeps every row and grows down the sequence you name.
- Does the running-total query work in Snowflake, BigQuery, or MySQL?
- The pattern is ANSI-standard: `SUM(amount) OVER (ORDER BY day)` runs unchanged on Postgres, Snowflake, BigQuery, and MySQL 8+. Older MySQL (< 8.0) has no window functions, so it needs a self-join or session variable instead. nlqdb runs your ask on Postgres today and shows the compiled SQL — the running total it writes is the same clause you'd paste into any modern warehouse.