- How do I get the top N rows per group without writing window-function SQL?
- Ask in plain English — 'top 3 products per category by revenue.' nlqdb compiles the canonical `ROW_NUMBER() OVER (PARTITION BY category ORDER BY revenue DESC)` filtered to rank ≤ 3, runs it in Postgres, and returns the ranked rows plus the SQL it ran. You get the per-group top-N without hand-writing a window function or a correlated subquery. The honest limit: it's a one-off ranked answer, not a saved dashboard.
- What SQL does nlqdb use to rank rows within each group?
- The modern pattern: a window function — `ROW_NUMBER() OVER (PARTITION BY <group> ORDER BY <metric> DESC)` in a subquery, then keep rows where the rank is ≤ N. nlqdb writes and runs that for you and shows it under a trace toggle, so you can confirm it partitioned by the right column. Ask for ties-included ranking and it switches `ROW_NUMBER` to `RANK` or `DENSE_RANK`.
- Can I rank rows in 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 the top-N question 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 ranking with a read-only query — it doesn't persist a materialized leaderboard for you.
- Why not just ask ChatGPT for the top N per group?
- A chat model can write you a window-function query, but it can't run it against your data — and if you paste rows in and ask it to rank, it miscounts or invents rows. nlqdb runs the actual SQL in Postgres and returns the real ranked rows plus the query it ran, so the top-N is computed, not guessed.