sql-explainer
Skill1 starsChanged 19 days agoMITView on GitHub
Walk through a pasted SQL query in execution order in plain language: what each step does, the grain of the result, where a join can fan rows out, which filters silently drop rows, and a ranked list of what could be wrong. Comprehension only, not performance tuning. Use when you inherited a query, are reviewing one before trusting its numbers, or have to explain it to someone who does not read SQL.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- rpmcdougall/claude-skillstheir own version, first seen Nov 22, 2026
- mergisi/awesome-openclaw-agentstheir own version, first seen Nov 1, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- mergisi/awesome-openclaw-agents★ 4.1ksame name
- rpmcdougall/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository168 other files it gives its agents.
- agents.mdAGENTS.md
- 3d-asset-handoff-sheetSkill
- accessibility-regression-auditorSkill
- adr-writerSkill
- agent-memory-designerSkill
- agent-trajectory-evaluatorSkill
- alerting-rules-tunerSkill
- analysis-memo-writerSkill
- annotation-disagreement-ledgerSkill
- annotation-task-spec-builderSkill
- api-deprecation-plannerSkill
- api-error-contract-designerSkill
- architecture-diagram-generatorSkill
- asset-metadata-review-ledgerSkill
- auth-flow-reviewerSkill
- avatar-video-script-writerSkill
- background-job-reliability-auditorSkill
- branch-rebaserSkill
- brand-voice-profilerSkill
- bundle-analyzerSkill
- cache-policy-designerSkill
- canary-release-plannerSkill
- caption-correction-ledgerSkill
- changelog-from-prsSkill
- chart-chooserSkill
- chunking-strategy-optimizerSkill
- circular-dependency-breakerSkill
- claude-settings-auditorSkill
- code-example-verifierSkill
- cold-email-deliverability-auditorSkill
- cold-start-optimizerSkill
- commit-splitterSkill
- competitor-teardownSkill
- component-spec-writerSkill
- connection-pool-tunerSkill
- content-repurposerSkill
- contract-obligation-registerSkill
- contract-test-designerSkill
- conventional-commitsSkill
- cors-configuratorSkill
- coverage-gap-finderSkill
- crm-export-auditorSkill
- dashboard-designerSkill
- data-retention-auditorSkill
- dataset-first-lookSkill
- dead-code-finderSkill
- deadlock-diagnoserSkill
- decision-log-reconcilerSkill
- dependency-auditSkill
- dependency-upgrade-plannerSkill
- design-brief-writerSkill
- design-critique-checklistSkill
- design-token-extractorSkill
- devcontainer-designerSkill
- distributed-tracing-instrumenterSkill
- dockerfile-optimizerSkill
- email-sequence-drafterSkill
- embedding-index-tunerSkill
- embedding-set-inspectorSkill
- entity-match-candidate-ledgerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Restate the query's apparent purpose in one sentence: before explaining any of it, so the reader can immediately see whether the query does …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Most of the SQL an analyst is asked to trust was written by somebody else, often somebody who has left. This skill reads a pasted query the way you would read it out loud to a colleague: in the order the database actually resolves it, saying what each step does to the rows, and ending on the two questions that decide whether the output is usable. What is one row of the result, and which rows never made it here? It is comprehension, not tuning, and it needs no connection, no plan, and no shell, so it runs identically on claude.ai, in Claude Code, and in Claude Cowork.
When to use this skill
- You inherited a dashboard query and have to defend its numbers in a meeting.
- A metric looks wrong and you want the query read carefully before the data is blamed.
- You are reviewing someone's query and want a structured read rather than a skim.
- You have to explain what a query does to a stakeholder who does not read SQL.
[!NOTE] This skill does not tune performance. It never proposes an index, reasons about a plan, or claims a rewrite is faster. When the question is "why is this slow", use the sql-optimizer skill, which reads a real
EXPLAIN ANALYZEand measures the fix. It also does not run the query, so every statement about row counts is conditional on the data, and it says so.
Instructions
- Note the dialect and what you can see. Identify the dialect from the syntax where it is visible (Postgres, BigQuery, Snowflake, MySQL) and say when you cannot tell. List what the query references but you were not given: table definitions, column nullability, whether a "table" is really a view. Every later claim is conditional on those unknowns and should be phrased that way.
- Restate the query's apparent purpose in one sentence before explaining any of it, so the reader can immediately see whether the query does what its name implies.
- Walk it in execution order, not written order.
FROMandJOIN, thenWHERE,GROUP BY, aggregates,HAVING, window functions,SELECT,DISTINCT,ORDER BY,LIMIT. For a CTE chain, take each CTE in dependency order and state its grain before moving on. One short paragraph per step: what comes in, what it does, what comes out. - State the grain of the result explicitly. One sentence: "one row per customer per calendar month, for customers with at least one order in the window". Then state the grain of every intermediate step where it changes, because a grain change in the middle of a query is where most double counting is born.
- Find the join fan-out. For each join, say which side can match more than once and what that does downstream. Name the classic pattern: a one-to-many join before an aggregate inflates every
SUMandCOUNTfrom the "one" side, so revenue gets multiplied by the number of line items. Say which aggregates here are exposed, and give the check: count rows before and after the join, or count distinct on the key. - List the filters that silently drop rows, working through them all: an inner join where a left join was meant, so unmatched rows vanish without a trace; a
WHEREcondition on a nullable column, sinceNULLfails every comparison including!=, so rows with nulls disappear from both sides of what looks like an exhaustive split; aWHEREclause on the right-hand table of aLEFT JOIN, which quietly turns it into an inner join; date boundaries, whereBETWEENincludes both ends and a timestamp compared against a date drops everything after midnight;NOT INagainst a subquery containing one null, which returns nothing at all; andHAVINGremoving whole groups after aggregation. - Check the aggregates against the grain. Whether
COUNT(*),COUNT(column), andCOUNT(DISTINCT column)are each the right one where used; whether an average of an average is being taken; whether a window'sPARTITION BYmatches the grain the reader assumes; and whetherDISTINCTis hiding a fan-out instead of fixing it. - Write the "what could be wrong" list, ranked. Each item names the risk, the line or CTE it lives on, and the specific check that would settle it, phrased so someone can run it: "run the query with the join removed and compare
COUNT(*)", "check whetherrefunded_atis nullable", "re-run with the end date pushed one day out and see whether the total moves". Rank by how much the number would move if the risk is real. - Close with a plain-language summary a non-SQL reader can use: three or four sentences ending with the grain and the caveat that matters most.
Output
An explanation in the order above: dialect and unknowns, purpose, the execution-order walkthrough, the grain statement, the fan-out analysis, the silent-drop list, the aggregate check, the ranked what-could-be-wrong list with its checks, and the plain-language summary. Paste the summary into the thread and keep the checks for the rerun. When the query defines a metric other people will use, /define-metric turns your reading of it into a written definition with a grain and an owner. When it sits inside a finished analysis, the analysis-reviewer agent runs these checks across the notebook, the SQL, and the prose together.
Example
Excerpt from a reading of a monthly revenue query:
Grain: one row per customer per month. The `orders` to `order_items` join is one-to-many.
Fan-out: `SUM(orders.total)` is computed after joining `order_items`, so every order's total is counted
once per line item. An order with 3 items contributes 3x. Check: compare `SUM(o.total)` before the join
with the current figure; they should be equal and probably are not.
Silently dropped rows:
- `JOIN customers` is an inner join, so orders from deleted customers are absent. Nothing in the output
says so.
- `WHERE o.canceled_at IS NULL` is correct, but the parallel query that reports cancellations uses
`WHERE o.canceled_at != ''`, which drops nulls; the two will not reconcile.
- `BETWEEN '2026-08-01' AND '2026-08-31'` on a timestamp column drops everything after midnight on the
31st. Check: push the bound to `< '2026-09-01'` and see whether the total moves.Turning natural language into SQL, and back, is covered in text-to-SQL and in Claude skills for data analysts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

