sql-query-explainer
$
npx mdskill add mohitagw15856/pm-claude-skills/sql-query-explainerThis 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.
SKILL.md
.github/skills/sql-query-explainerView on GitHub ↗
--- name: sql-query-explainer description: "Explain, optimise, or translate SQL queries into plain language. Use when asked to explain a SQL query, optimise slow SQL, write a data dictionary, translate SQL to plain English for non-technical stakeholders, or review a query for correctness and performance. 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. ## 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:** ```sql -- 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.] ``` --- ## 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 ## 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?"
More from mohitagw15856/pm-claude-skills
- 360-feedback-templateDesign 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.
- ab-test-plannerDesign 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.
- accessibility-auditGenerate 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.
- account-planBuild 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.
- aeo-optimizerOptimize an article for Answer Engine Optimization (AEO) — restructuring content so AI engines like ChatGPT, Perplexity, and Claude can extract, quote, and cite it. Rewrites headings as questions, drops 50-80 word answer capsules, audits paragraph length, and flags trust signals. Use when asked to AEO-optimize, make content AI-readable, improve AI citation chances, or adapt an article for answer engines.
- ai-ethics-reviewConduct an ethical review of an AI or ML feature, model, or product. Use when asked to run an AI ethics review, assess AI risks, audit a model for bias, or produce an AI impact assessment. Produces a structured ethics review covering fairness, transparency, privacy, safety, accountability, and societal impact with prioritised mitigations.
- ai-product-canvasStructure AI and ML product decisions with the rigour of any product decision. Use when building AI-powered features, evaluating LLM integrations, designing AI products, or assessing AI readiness. Produces a complete AI product canvas covering problem definition, model approach, data requirements, evaluation framework, UX design, responsible AI checklist, and launch monitoring plan.
- ambiguity-resolverStructure vague opportunities and unclear briefs into actionable one-page problem statements. Use when asked to clarify a vague brief, frame an undefined problem, make sense of an unclear opportunity, or when the user says 'we need to figure out what to do about X' or 'I've been asked to look into Y'. Produces a structured problem brief with reframed questions, scoped boundaries, and a minimum viable research plan.
- api-docs-writerWrite clear, developer-facing API documentation. Use when asked to document an API endpoint, write API reference docs, create a developer guide, or turn a raw spec/Postman collection into documentation. Produces endpoint documentation with descriptions, parameters, request/response examples, and error codes.
- api-versioning-strategyWrite an API versioning strategy document for a service or API platform. Use when asked to define versioning policy, plan API deprecation, classify breaking changes, or document version lifecycle. Produces a complete versioning strategy with breaking-change classification table, deprecation timeline, migration guide template, and client communication template.