Turn a Question Into a SQL Query

Describe your tables and ask in plain English; get a correct, dialect-aware SQL query with a short explanation.

0 likes 0 dislikes
Sign in to rate this prompt

Prompt

    Write a SQL query that answers the question below.

Question (in plain English):
{{question}}

Database dialect (e.g. PostgreSQL, MySQL, SQLite, BigQuery): {{dialect}}

Schema — paste the relevant CREATE TABLE statements, or describe the tables and columns:
{{schema}}

Please:
1. Return the query, formatted and readable, using only tables and columns that exist in the schema above.
2. Explain in a sentence or two what it does and any assumption you made (for example, how you interpreted "active" or "last month").
3. If the schema doesn't contain what's needed to answer the question, say what's missing instead of inventing columns.

Prefer clarity over cleverness. Note if there's an index or a rewrite that would matter for performance on a large table.

Like this prompt?

Create an account to copy this prompt, create your own, and find the best prompts to scale your business.