Skip to content
Shelf

The public shelf

A library for prompts you reuse. Write them, version them, test them, and keep the ones that work. Copy one as it is, or fork it and make it yours.

1 prompt · Clear filters

Write a SQL query from a question in plain English

Turns a question about your data into a query, states every assumption it had to make, and explains the result so you can check it is answering the right thing.

Write a SQL query that answers my question.

Database: {{database:PostgreSQL}}
My question: {{question}}

Tables and columns (paste the schema, or describe the tables, their columns, and how they relate):
{{schema}}

Give me:
1. The query, formatted, with a short comment above any part that is not obvious.
2. A plain-English walkthrough: which tables it reads, how they are joined, what is filtered out, and how the result is grouped and sorted.
3. Every assumption you made. Common ones: what counts as "active" or "recent", how nulls are treated, whether time ranges include their end date, which time zone dates are in, and whether rows can be duplicated by a join.
4. What the output will look like: the columns, and one or two example rows.
5. A quick check I can run to confirm that the number is right, such as a count before and after the join.

Rules:
- Use only tables and columns from the schema I gave. If something I need is not there, say what is missing; do not make up a column.
- Use syntax that works in the database I named.
- If my question could mean two different things, write both queries and explain what distinguishes them.
- Watch for joins that multiply rows and inflate sums or counts. Call it out if that is a risk here.
- If the query could be slow on a large table, say which index would help.
- This is for reading data. Do not write anything that changes or deletes data unless I ask for it.
Arjun Menon · Data