Agent Skillsmohitagw15856/pm-claude-skills › sql-query-explainer

sql-query-explainer

GitHub

用于解释、优化、编写和文档化SQL查询的助手。支持将SQL转化为自然语言,识别性能瓶颈并提供改进建议,根据自然语言描述生成SQL,以及产出数据字典。适用于PostgreSQL、MySQL等多种方言。

exports/openclaw/sql-query-explainer/SKILL.md mohitagw15856/pm-claude-skills

Trigger Scenarios

解释SQL查询逻辑 优化慢速SQL语句 将SQL翻译为业务人员易懂的语言 根据自然语言需求编写SQL 生成SQL查询文档或数据字典

Install

npx skills add mohitagw15856/pm-claude-skills --skill sql-query-explainer -g -y
More Options

Non-standard path

npx skills add https://github.com/mohitagw15856/pm-claude-skills/tree/main/exports/openclaw/sql-query-explainer -g -y

Use without installing

npx skills use mohitagw15856/pm-claude-skills@sql-query-explainer

指定 Agent (Claude Code)

npx skills add mohitagw15856/pm-claude-skills --skill sql-query-explainer -a claude-code -g -y

安装 repo 全部 skill

npx skills add mohitagw15856/pm-claude-skills --all -g -y

预览 repo 内 skill

npx skills add mohitagw15856/pm-claude-skills --list

SKILL.md

Frontmatter
{
    "name": "sql-query-explainer",
    "homepage": "https:\/\/mohitagw15856.github.io\/pm-claude-skills\/skill\/sql-query-explainer.html",
    "metadata": {
        "openclaw": {
            "emoji": "📊"
        }
    },
    "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:

  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?"

Version History

  • 54fad50 Current 2026-07-19 12:34

Same Skill Collection

exports/openclaw/360-feedback-template/SKILL.md
exports/openclaw/401k-plan-decoder/SKILL.md
exports/openclaw/ab-test-planner/SKILL.md
exports/openclaw/ab-test-readout/SKILL.md
exports/openclaw/accessibility-audit/SKILL.md
exports/openclaw/account-plan/SKILL.md
exports/openclaw/acquirer-red-team/SKILL.md
exports/openclaw/ad-copy/SKILL.md
exports/openclaw/aeo-optimizer/SKILL.md
exports/openclaw/agenda-or-cancel/SKILL.md
exports/openclaw/agent-design-review/SKILL.md
exports/openclaw/agent-observability-spec/SKILL.md
exports/openclaw/agent-spec/SKILL.md
exports/openclaw/ai-ethics-review/SKILL.md
exports/openclaw/ai-eval-plan/SKILL.md
exports/openclaw/ai-feature-prd/SKILL.md
exports/openclaw/ai-product-canvas/SKILL.md
exports/openclaw/air-quality/SKILL.md
exports/openclaw/altitude-shifter/SKILL.md
exports/openclaw/ambiguity-resolver/SKILL.md
exports/openclaw/analyst-relations-brief/SKILL.md
exports/openclaw/announcement-card/SKILL.md
exports/openclaw/api-docs-writer/SKILL.md
exports/openclaw/api-test-plan/SKILL.md
exports/openclaw/api-versioning-strategy/SKILL.md
exports/openclaw/apology-letter/SKILL.md
exports/openclaw/architecture-decision-record/SKILL.md
exports/openclaw/architecture-diagram/SKILL.md
exports/openclaw/archive-strategy/SKILL.md
exports/openclaw/assumption-bounty/SKILL.md
exports/openclaw/assumption-mapper/SKILL.md
exports/openclaw/async-update-format/SKILL.md
exports/openclaw/auto-repair-estimate-decoder/SKILL.md
exports/openclaw/autopilot-charter/SKILL.md
exports/openclaw/benefits-decoder/SKILL.md
exports/openclaw/bid-tender-review/SKILL.md
exports/openclaw/board-deck-narrative/SKILL.md
exports/openclaw/board-minutes/SKILL.md
exports/openclaw/board-pre-read/SKILL.md
exports/openclaw/bom-cost-review/SKILL.md
exports/openclaw/bookkeeping-categorization/SKILL.md
exports/openclaw/boolean-search-builder/SKILL.md
exports/openclaw/brag-doc/SKILL.md
exports/openclaw/brainstorming/SKILL.md
exports/openclaw/brief-builder/SKILL.md
exports/openclaw/briefing-note/SKILL.md
exports/openclaw/budget-builder/SKILL.md
exports/openclaw/budget-variance-analysis/SKILL.md
exports/openclaw/bug-diagnosis/SKILL.md
exports/openclaw/bug-report/SKILL.md

Metadata

Files
0
Version
471c606
Hash
27c24713
Indexed
2026-07-19 12:34

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-30 11:14
浙ICP备14020137号-1 $방문자$