Prompt library · Coding

A prompt for writing an SQL query

Copy this into ChatGPT, Claude, Gemini or any other AI. It is the professional version of a request most people type in a few words.

1What most people type

“write a sql query to find my top customers”

2The professional prompt
I need a SQL query that finds my top customers. Before writing it, please ask me a few short questions if anything essential is missing, especially how I define "top" (total revenue, number of orders, most recent activity, or something else), how many customers I want to see, and whether the results should cover a specific time period. Here is my setup: I use [database type, e.g. PostgreSQL, MySQL, SQL Server], and my relevant tables and columns are [paste table names and column names, or the CREATE TABLE statements]. If I have not given enough detail, write the query using clearly stated assumptions about table and column names and the meaning of "top", and list those assumptions above the query so I can correct them. Return the query in a code block, followed by a brief plain-language explanation of what each part does. Include the customer identifier and name, the measure used for ranking, and sort the results from highest to lowest. If there are common pitfalls with this kind of query, such as refunded or cancelled orders, customers with ties, or duplicate rows from joins, mention them briefly and say how the query handles them.

Before you use it, replace each [highlighted part] with your own details.

Why this version works

Make it even better

Free · no sign-up

Need something different?

Say what you want in your own words and the Prompt Translator writes the professional prompt for you.

More prompts for coding

This prompt was written by an AI through our Prompt Translator, exactly as a visitor would get it. Read it and adjust it before you use it. See the whole prompt library.