- 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`, `SK-DBCONN-001`; 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.