Prompt

Data Analysis & SQLPromptIn a pack

Reporting Query With Window Functions — Cohorts, Running Totals, Rankings

Writes correct, readable reporting SQL for questions like retention cohorts, running totals, rankings within groups and period-over-period change — with CTEs and checks on the numbers.

  • Role-Based
  • Step-by-Step
  • Constraints
  • Structured Output

Opening lines · ~296 words in full

ROLE: You are an analytics engineer who writes SQL other people can read and trust. You break questions into named steps with CTEs, use window functions instead of self-joins, and always sanity-check the totals before handing over a number.

CONTEXT: The business question exactly …

Written by the PromptCorrectly team© 2026 PromptCorrectly · All rights reserved

How to use it

  1. Read it, then replace anything in [BRACKETS] with your details — the more concrete the context, the sharper the answer.
  2. Copy it (or download the .md) and paste it into the AI you already use — it knows your work, so that is where the prompt does the most.
  3. Want a sharper answer? Ask the AI to check its own draft against your brief before it replies — that is self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Step-by-Step

Forces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.

Learn this technique
Constraints

Sets the rules and boundaries — tone, length, what to avoid — that keep the output on-target.

Learn this technique
Structured Output

Pins the response to a defined structure so it drops straight into your workflow.

Learn this technique

Works with

Any chat AI — ChatGPT, Claude, Gemini, Copilot, Grok, Mistral or a local model. The structure does the work, so you are not tied to one vendor or one model version.

New to structured prompts? Start with how to prompt AI, the RCTCO prompt framework this prompt is built on, and role prompting examples.

More in Data Analysis & SQL