New: Earn 20% as an AgentAlley affiliate. Share your link and earn on every sale you refer. Join now New: Earn 20% as an affiliate. Join now

Explains, optimises, writes, and documents SQL queries

SQL Query Explainer Skill

by mohitagw15856 · MIT license · ★ 1,395 on GitHub · updated Sep 23

SQL Query Explainer Skill cover

Explains, optimises, writes, and documents SQL queries. Use when asked to explain a SQL query, optimise slow SQL, translate SQL to plain English for non-technical stakeholders, write a query from a natural language description, or…

---
name: sql-query-explainer
description: "Explains, optimises, writes, and documents SQL queries. Use when asked to explain a SQL query, optimise slow SQL, translate SQL to plain English for non-technical stakeholders, write a query from a natural language description, or produce query documentation. Produces plain-English explanations, annotated optimised queries, or a data dictionary covering output shape, assumptions, and known limitations. Works across PostgreSQL, MySQL, BigQuery, Snowflake, and standard SQL."
---

# SQL Query Explainer Skill

This skill explains SQL queries in plain language, identifies optimisation opportunities, and helps communicate data logic to non-technical stakeholders. It also writes and documents new queries from natural language descriptions.

## Required Inputs

- **The SQL** (Explain/Optimise/Document modes) — the actual query, ideally with the dialect named (Postgres, BigQuery, Snowflake, MySQL…); dialect changes both semantics and the optimisation advice.
- **The intent in plain words** (Write mode) — what question the data should answer, plus table/column names if known. Without a schema, assumptions get stated, never silently invented.
- Optional but transformative: `EXPLAIN`/`EXPLAIN ANALYZE` output and rough table sizes — turns generic advice into advice about *your* query plan.

## Modes

Detect which mode the user needs based on their request:

Overview

This skill explains SQL queries in plain language, identifies optimisation opportunities, and helps communicate data logic to non-technical stakeholders. It also writes and documents new queries from natural language descriptions.

What you get

  • The one-line summarywhat this query does, in business language ("monthly revenue per region, excluding refunds"), before any SQL talk.
  • The walkthrough or the artifactmode-dependent: annotated clause-by-clause explanation (Explain), the rewritten query with a diff of what changed and why (Optimise), the new query with stated assumptions (Write), or the doc block (Document).
  • The gotchasNULL behaviour, join fan-out, timezone traps, and index implications that apply to this query, not generic advice.
  • Verificationa small SELECT the user can run to confirm the query does what the summary claims (row counts before/after, a spot-check predicate).
Manual install (npx, ZIP)
Claude Codenpx skills add mohitagw15856/pm-claude-skills --skill sql-query-explainer -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/mohitagw15856/pm-claude-skills/tar.gz/f6ca79348c55 \ | tar -xz -C ~/.claude/skills --strip-components=2 pm-claude-skills-f6ca79348c55/skills/sql-query-explainer
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/e3f90881936417191f0a/sql-query-explainer.zip" -OutFile "$env:TEMP\sql-query-explainer.zip"; Expand-Archive "$env:TEMP\sql-query-explainer.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md6.2 KB
Read the files here
mohitagw15856/f6ca7931 file
SKILL.md
Show the full text167 lines

SQL Query Explainer Skill

This skill explains SQL queries in plain language, identifies optimisation opportunities, and helps communicate data logic to non-technical stakeholders. It also writes and documents new queries from natural language descriptions.

Required Inputs

  • The SQL (Explain/Optimise/Document modes) — the actual query, ideally with the dialect named (Postgres, BigQuery, Snowflake, MySQL…); dialect changes both semantics and the optimisation advice.
  • The intent in plain words (Write mode) — what question the data should answer, plus table/column names if known. Without a schema, assumptions get stated, never silently invented.
  • Optional but transformative: EXPLAIN/EXPLAIN ANALYZE output and rough table sizes — turns generic advice into advice about your query plan.

Modes

Detect which mode the user needs based on their request:

  1. Explain — Translate existing SQL into plain English
  2. Optimise — Review SQL for performance issues and suggest improvements
  3. Write — Generate SQL from a natural language description
  4. Document — Produce a data dictionary or query documentation

Mode 1: Explain

When given a SQL query, produce:

Plain English Summary

[1–3 sentences. What does this query do? What data does it return? Write as if explaining to a business analyst, not a developer.]

Step-by-Step Walkthrough

Break the query into logical sections. For each section:

  • Quote the SQL clause
  • Explain what it does in plain English
  • Flag any complexity (e.g. window functions, subqueries, CTEs)
What the Result Looks Like

[Describe the shape of the output: "Returns one row per user, with columns for X, Y, Z. Ordered by [field] descending."]

Potential Issues to Flag
  • [Gotchas, edge cases, or implicit assumptions in this query]
  • [e.g. "This will include NULLs in the user_id column if the LEFT JOIN finds no match"]

Mode 2: Optimise

When asked to optimise a query, produce:

Performance Assessment

Rate overall: 🟢 Well-optimised / 🟡 Some improvements possible / 🔴 Significant issues

Issues Found

For each issue:

Issue [N]: [Short name, e.g. "Missing index on join column"]

  • What it is: [Plain explanation]
  • Why it matters: [Performance impact — e.g. "Full table scan on a 10M row table"]
  • Fix:
-- Before
[original snippet]

-- After
[improved snippet]
  • Expected improvement: [Estimate if possible]
Optimisation Checklist
  • SELECT * used? (Replace with specific columns)
  • Implicit type conversions on JOIN/WHERE columns?
  • Missing indexes on JOIN or WHERE columns?
  • N+1 patterns (queries inside loops)?
  • DISTINCT used where GROUP BY would be faster?
  • Window functions used where a subquery would be clearer/faster?
  • CTEs re-used or materialised unnecessarily?
  • Large IN() lists that could use a JOIN instead?

Mode 3: Write

When given a natural language description, generate the SQL query and then explain it using Mode 1.

Ask the user to confirm:

  • Database/dialect (PostgreSQL / MySQL / BigQuery / Snowflake / SQLite / Standard SQL)
  • Table and column names (if known; otherwise use descriptive placeholder names like users, orders, user_id)
  • Any filters, sorting, or aggregation requirements

Produce:

  1. The SQL query with inline comments
  2. Plain English explanation (Mode 1 format)

Mode 4: Document

When asked to create documentation for a query or table:

Query Documentation
Query: [Name]
Purpose: [One sentence — what business question this answers]
Author: [If provided]
Last reviewed: [If provided]

Inputs:
  - Table: [table_name] — [what it contains]
  - Filter: [any WHERE conditions and their business meaning]

Output columns:
  | Column | Type | Description |
  |--------|------|-------------|
  | [name] | [type] | [plain English description] |

Assumptions:
  - [Any implicit assumptions the query makes]

Known limitations:
  - [Edge cases not handled, data quality dependencies, etc.]

Output Format

Every mode returns the same disciplined shape:

  1. The one-line summary — what this query does, in business language ("monthly revenue per region, excluding refunds"), before any SQL talk.
  2. The walkthrough or the artifact — mode-dependent: annotated clause-by-clause explanation (Explain), the rewritten query with a diff of what changed and why (Optimise), the new query with stated assumptions (Write), or the doc block (Document).
  3. The gotchas — NULL behaviour, join fan-out, timezone traps, and index implications that apply to this query, not generic advice.
  4. Verification — a small SELECT the user can run to confirm the query does what the summary claims (row counts before/after, a spot-check predicate).

Quality Checks

  • Plain English explanation avoids SQL jargon
  • Optimisation suggestions include before/after SQL
  • Written queries include inline comments
  • Output shape is described (columns, row grain, ordering)
  • Dialect-specific syntax is flagged when non-standard

Anti-Patterns

  • Restating the SQL in pseudo-code instead of explaining what it does and returns
  • Optimisation advice with no before/after query, or no reason the new one is faster
  • Ignoring the dialect (writing Postgres-only syntax for a MySQL user)
  • "Looks fine" with no read on correctness, performance, or row grain
  • Rewriting the query from scratch instead of explaining/optimising the user's

Example Trigger Phrases

  • "Explain this SQL query: [paste query]"
  • "Optimise this slow query: [paste query]"
  • "Write a SQL query that [natural language description]"
  • "Document this query for my non-technical stakeholders"
  • "Why is this query returning unexpected results?"
1---
2name: sql-query-explainer
3description: "Explains, optimises, writes, and documents SQL queries. Use when asked to explain a SQL query, optimise slow SQL, translate SQL to plain English for non-technical stakeholders, write a query from a natural language description, or produce query documentation. Produces plain-English explanations, annotated optimised queries, or a data dictionary covering output shape, assumptions, and known limitations. Works across PostgreSQL, MySQL, BigQuery, Snowflake, and standard SQL."
4---
5 
6# SQL Query Explainer Skill
7 
8This skill explains SQL queries in plain language, identifies optimisation opportunities, and helps communicate data logic to non-technical stakeholders. It also writes and documents new queries from natural language descriptions.
9 
10## Required Inputs
11 
12- **The SQL** (Explain/Optimise/Document modes) — the actual query, ideally with the dialect named (Postgres, BigQuery, Snowflake, MySQL…); dialect changes both semantics and the optimisation advice.
13- **The intent in plain words** (Write mode) — what question the data should answer, plus table/column names if known. Without a schema, assumptions get stated, never silently invented.
14- Optional but transformative: `EXPLAIN`/`EXPLAIN ANALYZE` output and rough table sizes — turns generic advice into advice about *your* query plan.
15 
16## Modes
17 
18Detect which mode the user needs based on their request:
19 
201. **Explain** — Translate existing SQL into plain English
212. **Optimise** — Review SQL for performance issues and suggest improvements
223. **Write** — Generate SQL from a natural language description
234. **Document** — Produce a data dictionary or query documentation
24 
25---
26 
27## Mode 1: Explain
28 
29When given a SQL query, produce:
30 
31### Plain English Summary
32[1–3 sentences. What does this query do? What data does it return? Write as if explaining to a business analyst, not a developer.]
33 
34### Step-by-Step Walkthrough
35 
36Break the query into logical sections. For each section:
37- Quote the SQL clause
38- Explain what it does in plain English
39- Flag any complexity (e.g. window functions, subqueries, CTEs)
40 
41### What the Result Looks Like
42 
43[Describe the shape of the output: "Returns one row per user, with columns for X, Y, Z. Ordered by [field] descending."]
44 
45### Potential Issues to Flag
46 
47- [Gotchas, edge cases, or implicit assumptions in this query]
48- [e.g. "This will include NULLs in the user_id column if the LEFT JOIN finds no match"]
49 
50---
51 
52## Mode 2: Optimise
53 
54When asked to optimise a query, produce:
55 
56### Performance Assessment
57 
58Rate overall: 🟢 Well-optimised / 🟡 Some improvements possible / 🔴 Significant issues
59 
60### Issues Found
61 
62For each issue:
63 
64**Issue [N]: [Short name, e.g. "Missing index on join column"]**
65- **What it is:** [Plain explanation]
66- **Why it matters:** [Performance impact — e.g. "Full table scan on a 10M row table"]
67- **Fix:**
68```sql
69-- Before
70[original snippet]
71 
72-- After
73[improved snippet]
74```
75- **Expected improvement:** [Estimate if possible]
76 
77### Optimisation Checklist
78 
79- [ ] SELECT * used? (Replace with specific columns)
80- [ ] Implicit type conversions on JOIN/WHERE columns?
81- [ ] Missing indexes on JOIN or WHERE columns?
82- [ ] N+1 patterns (queries inside loops)?
83- [ ] DISTINCT used where GROUP BY would be faster?
84- [ ] Window functions used where a subquery would be clearer/faster?
85- [ ] CTEs re-used or materialised unnecessarily?
86- [ ] Large IN() lists that could use a JOIN instead?
87 
88---
89 
90## Mode 3: Write
91 
92When given a natural language description, generate the SQL query and then explain it using Mode 1.
93 
94Ask the user to confirm:
95- **Database/dialect** (PostgreSQL / MySQL / BigQuery / Snowflake / SQLite / Standard SQL)
96- **Table and column names** (if known; otherwise use descriptive placeholder names like `users`, `orders`, `user_id`)
97- **Any filters, sorting, or aggregation requirements**
98 
99Produce:
1001. The SQL query with inline comments
1012. Plain English explanation (Mode 1 format)
102 
103---
104 
105## Mode 4: Document
106 
107When asked to create documentation for a query or table:
108 
109### Query Documentation
110 
111```
112Query: [Name]
113Purpose: [One sentence — what business question this answers]
114Author: [If provided]
115Last reviewed: [If provided]
116 
117Inputs:
118 - Table: [table_name] — [what it contains]
119 - Filter: [any WHERE conditions and their business meaning]
120 
121Output columns:
122 | Column | Type | Description |
123 |--------|------|-------------|
124 | [name] | [type] | [plain English description] |
125 
126Assumptions:
127 - [Any implicit assumptions the query makes]
128 
129Known limitations:
130 - [Edge cases not handled, data quality dependencies, etc.]
131```
132 
133---
134 
135## Output Format
136 
137Every mode returns the same disciplined shape:
138 
1391. **The one-line summary** — what this query does, in business language ("monthly revenue per region, excluding refunds"), before any SQL talk.
1402. **The walkthrough or the artifact** — mode-dependent: annotated clause-by-clause explanation (Explain), the rewritten query with a diff of what changed and why (Optimise), the new query with stated assumptions (Write), or the doc block (Document).
1413. **The gotchas** — NULL behaviour, join fan-out, timezone traps, and index implications that apply to *this* query, not generic advice.
1424. **Verification** — a small `SELECT` the user can run to confirm the query does what the summary claims (row counts before/after, a spot-check predicate).
143 
144## Quality Checks
145 
146- [ ] Plain English explanation avoids SQL jargon
147- [ ] Optimisation suggestions include before/after SQL
148- [ ] Written queries include inline comments
149- [ ] Output shape is described (columns, row grain, ordering)
150- [ ] Dialect-specific syntax is flagged when non-standard
151 
152## Anti-Patterns
153 
154- Restating the SQL in pseudo-code instead of explaining what it *does* and *returns*
155- Optimisation advice with no before/after query, or no reason the new one is faster
156- Ignoring the dialect (writing Postgres-only syntax for a MySQL user)
157- "Looks fine" with no read on correctness, performance, or row grain
158- Rewriting the query from scratch instead of explaining/optimising the user's
159 
160## Example Trigger Phrases
161 
162- "Explain this SQL query: [paste query]"
163- "Optimise this slow query: [paste query]"
164- "Write a SQL query that [natural language description]"
165- "Document this query for my non-technical stakeholders"
166- "Why is this query returning unexpected results?"
167 
View all files on GitHub →

Details

Updated
Sep 23, 2026
License
MIT
Stars on the repo
★ 1,395
Checked
Source
mohitagw15856/pm-claude-skills ↗
Creator
mohitagw15856 · 193 listings
View creator

Made with sql-query-explainer

SQL Query Explainer Skill — Galaxy 3D — fly through all 1170 skills as a glowing constellation you orbit and click into (from the mohitagw15856/pm-claude-skills README)
SQL Query Explainer Skill — Galaxy 3D — fly through all 1170 skills as a glowing constellation you orbit and click into (from the mohitagw15856/pm-claude-skills README)

by mohitagw15856

SQL Query Explainer Skill — PM Skills Wrapped — your practice turned into a shareable, Spotify-Wrapped-style story (from the mohitagw15856/pm-claude-skills README)
SQL Query Explainer Skill — PM Skills Wrapped — your practice turned into a shareable, Spotify-Wrapped-style story (from the mohitagw15856/pm-claude-skills README)

by mohitagw15856

Similar skills

See all →
PromptA prompt system for generating plain-language project"Explain It Like I Built It" Technical Documentation for Non-Technical Foundersf/prompts.chat · by Nureddin Gökbey İnaçA prompt system for generating plain-language project documentation. This prompt generates a [FORME].md (or any custom name) file a living document that explains your entire project in plain language. It's designed for non-technical founders, product owners, and designers who need to deeply understand the technical systems they're responsible for, without reading code. The document doesn't dumb things down. It makes complex things legible through analogy, narrative, and structure.New listingSkillPaste your messy brain-dump or voice-note and get backTurn your rambling notes into a clear briefShubhamsaboo/awesome-llm-apps · by Shubham SabooPaste your messy brain-dump or voice-note and get back a tidy brief: your goal, your decisions, what you changed your mind about, and the guesses you need to correct.★ 139k GitHub starsSkillApply before you trust, reportExplain the Numbermichael-denyer/pstack-claude · by michael-denyerApply before you trust, report, or act on a number you measured: a speedup, a regression, a throughput, a latency, or an eval result. Find what limits it, and rule out that it measured something other than the work you think.★ 1k GitHub starsPromptWrite a ${tone:professional|friendly} email to ${recipient}Write an emailf/prompts.chat · by Training AccountWrite a ${tone:professional|friendly} email to ${recipient} about ${topic}.New listingSkillGenerate SQL queries from natural language descriptionsSQL Query Generatorphuryn/pm-skills · by phurynGenerate SQL queries from natural language descriptions. Supports BigQuery, PostgreSQL, MySQL, and other dialects. Reads database schemas from uploaded diagrams or documentation. Use when writing SQL, building data reports, exploring databases, or translating business questions into queries.★ 26.6k GitHub starsSkillSummarize a meeting transcript into structured notesSummarize meetingphuryn/pm-skills · by phurynSummarize a meeting transcript into structured notes with date, participants, topic, key decisions, summary points, and action items. Use when processing meeting recordings, creating meeting notes, writing meeting minutes, or recapping discussions.★ 26.6k GitHub stars

More from mohitagw15856

SkillDesign a 360-degree feedback survey or write a structured360-Degree Feedback Template Skillmohitagw15856/pm-claude-skills · by mohitagw15856Design a 360-degree feedback survey or write a structured 360 feedback report. Use when asked to build a 360 feedback process, write 360 feedback for a colleague, design a feedback survey, or produce a feedback report. Produces either a complete survey instrument with rating scales and open-ended questions, or a structured narrative feedback report with themes, strengths, and development areas.★ 1.4k GitHub starsSkillDesign statistically rigorous A/B tests for product featuresA/B Test Planner Skillmohitagw15856/pm-claude-skills · by mohitagw15856Design statistically rigorous A/B tests for product features, UI changes, onboarding flows, and pricing experiments. Use when asked to set up an experiment, design an A/B test, calculate sample size, or interpret test results. Produces a complete test plan with hypothesis, variant definitions, sample size, duration estimate, guardrail metrics, and a results interpretation guide.★ 1.4k GitHub starsSkillGenerate a WCAG 2.2 accessibility audit checklistAccessibility Audit Skillmohitagw15856/pm-claude-skills · by mohitagw15856Generate a WCAG 2.2 accessibility audit checklist and remediation suggestions for any UI or design. Use when asked to audit for accessibility, check WCAG compliance, review a design for a11y issues, or create an accessibility remediation plan. Produces a prioritised checklist with pass/fail assessments and specific fixes.★ 1.4k GitHub starsSkillBuild a structured account plan for any key customerAccount Plan Skillmohitagw15856/pm-claude-skills · by mohitagw15856Build a structured account plan for any key customer or target account. Use when asked to create an account plan, key account strategy, strategic account review, or territory plan. Produces a complete account plan with relationship map, growth opportunities, risks, and 90-day action plan.★ 1.4k GitHub starsSkillOptimize an article for Answer Engine Optimization so AIAEO Optimizer Skillmohitagw15856/pm-claude-skills · by mohitagw15856Optimize an article for Answer Engine Optimization (AEO) so AI engines like ChatGPT, Perplexity, and Claude can extract, quote, and cite it. Use when asked to AEO-optimize, make content AI-readable, improve AI citation chances, or adapt an article for answer engines. Produces an AEO-optimised rewrite with question headings, 50–80 word answer capsules, a paragraph-length audit, and flagged trust signals.★ 1.4k GitHub starsSkillConduct a structured ethical review of an AI or ML featureAI Ethics Review Skillmohitagw15856/pm-claude-skills · by mohitagw15856Conduct a structured ethical review of an AI or ML feature, model, or product. Use when preparing to deploy an AI system, assessing algorithmic risk, auditing a model for bias, or producing a responsible AI impact assessment. Produces a structured ethics review covering fairness, transparency, privacy, safety, accountability, and societal impact with a risk tier score, pre-deployment checklist, and prioritised mitigations.★ 1.4k GitHub stars