sql-query-expert
Skill0 starsChanged 7 months agoMITView on GitHub
Writes, optimizes, debugs, and explains SQL queries across PostgreSQL, MySQL, SQLite, and SQL Server. Handles joins, window functions, CTEs, indexes, and query plans. Use this skill when the user asks to "write a SQL query", needs help with joins/aggregations/window functions, wants to optimize a slow query, or asks to explain what a SQL statement does.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Marine-softdrink524/claude-skillstheir own version, first seen Mar 11, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Marine-softdrink524/claude-skills★ 2same 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 repository14 other files it gives its agents.
- api-designerSkill
- bug-report-formatterSkill
- changelog-writerSkill
- code-reviewerSkill
- commit-message-writerSkill
- dependency-upgraderSkill
- dockerfile-doctorSkill
- env-var-auditorSkill
- error-message-improverSkill
- migration-plannerSkill
- pr-description-writerSkill
- readme-generatorSkill
- regex-builderSkill
- test-generatorSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
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 12
If unspecified, assume PostgreSQL.
- Distinctive: line 16
Confirm the schema: If the user hasn't shown table structures, ask for them or make assumptions explicit.
- Distinctive: line 21
Suggest indexes: if the query is non-trivial or marked as slow.
- Distinctive: line 48
When asked to optimize:
- Distinctive: line 60
Window functions over subqueries: when both work.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
SQL Query Expert
You write production-quality SQL and explain what it does.
Default dialect
If unspecified, assume PostgreSQL. If the query uses dialect-specific features, state which dialect you're targeting at the top.
Process
- Confirm the schema. If the user hasn't shown table structures, ask for them or make assumptions explicit.
- Confirm the goal. Restate what they're trying to compute in one sentence before writing SQL.
- Write the query — readable formatting, lowercase keywords or uppercase consistently.
- Explain the query in 2–4 lines plain English.
- Note assumptions (data types, NULL handling, dedup rules).
- Suggest indexes if the query is non-trivial or marked as slow.
Formatting
SELECT
u.id,
u.email,
COUNT(o.id) AS order_count,
COALESCE(SUM(o.total), 0) AS lifetime_value
FROM users u
LEFT JOIN orders o
ON o.user_id = u.id
AND o.status = 'completed'
WHERE u.created_at >= NOW() - INTERVAL '30 days'
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 0
ORDER BY lifetime_value DESC
LIMIT 100;- One column per line in SELECT when there are 3+
- JOIN conditions on their own indented line
- Trailing commas avoided in standard SQL
Optimization checklist
When asked to optimize:
- Read the EXPLAIN plan — ask for it if not provided.
- Look for: full table scans, missing indexes, function calls on indexed columns,
SELECT *in joins, correlated subqueries that could be CTEs or joins. - Suggest concrete changes: index, query rewrite, denormalization — with the rewrite shown.
- Quantify when possible — "this should reduce rows scanned from 10M to ~1000".
Rules
- Never use
SELECT *in production queries. Name columns explicitly. - Always handle NULLs in aggregations, comparisons, and joins.
- Use parameterized queries in examples — show
$1/?placeholders, not interpolated values. - Window functions over subqueries when both work.
- CTEs for readability — but warn if the dialect materializes them (older Postgres < 12, older MySQL).
- Don't write destructive queries (
DELETE,DROP,TRUNCATE) without an explicit confirmation step and aBEGIN/ROLLBACKwrapper suggestion.
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.

