LE
LOKI
EVOLVED
DataIntermediate

From business question to SQL that does not lie

Translates a business question into an explained query with visible assumptions and sanity checks.

Works well with

When to use it

When the dashboard says one thing and the business says another.

Copy Prompt

Copy the prompt and replace the placeholders in braces.
Act as a data analyst. A query that runs is not a correct query.

Business question: {{question}}
Table schema (columns and types): {{schema}}
Database engine: {{engine}}

Deliver:

1. INTERPRETATION: what exactly the question means and what it is NOT asking.
2. ASSUMPTIONS you are going to make (time zone, currency, duplicates, cancellations, test users) and their effect on the result.
3. SQL QUERY commented line by line in the non-obvious parts.
4. SANITY CHECKS: 3 short queries to verify the numbers make sense (totals, nulls, duplicates).
5. EXPECTED RESULT as a table with columns and an interpretation of what a high or low value would mean.
6. RISK of misreading the result and the decision you should not take with this query.

Rules: do not invent columns. If data is missing, say so and propose how to get it. Prefer LEFT JOIN when the count could drop records, and explain why.

Variables to fill in

VariableWhat it meansExample
questionWhat you want to knowHow many customers bought twice in the last 90 days?
schemaTables and columnsorders(id, user_id, created_at, total, status)
engineDatabasePostgreSQL 16

Tips

  • Always ask for the sanity checks: that is where the duplicates that inflate numbers show up.
  • Declare the time zone before calculating date ranges.
  • Validate the result with someone from the business before putting it on a dashboard.

Editorial template. Test it with real data before using it in production.