SQL Query Helper
Skill11 starsChanged 6 months agoMITView on GitHub
SQL dialect
In this repository37 other files it gives its agents.
- Browser ML in JavaScriptSkill
- CLI BuilderSkill
- ClickHouse Best PracticesSkill
- Code ReviewerSkill
- Code Review WorkflowSkill
- Commit Message WriterSkill
- deepeval Pytest Eval SuiteSkill
- deepeval OTel Trace ExportSkill
- deepeval SDK TracingSkill
- Doc Co-Authoring WorkflowSkill
- Embedding Model TrainingSkill
- Frontend Large-Feature ArchitectureSkill
- Frontend Visual Design TasteSkill
- Goal DefinitionSkill
- Internal Comms AuthoringSkill
- Invalid Name HandlerSkill
- LLM Model Pricing File UpdateSkill
- maf-prs-jobSkill
- MCP Server BuilderSkill
- Code Ownership & Bus FactorSkill
- PDF SummarizerSkill
- PDF Vision ExtractorSkill
- PNPM Upgrade PackageSkill
- promptflow-to-mafSkill
- promptfoo Eval Suite AuthorSkill
- promptfoo Redteam Plugin AuthorSkill
- Single-Flow PR YeetSkill
- React Router Search Param StateSkill
- Realtime Eval ScaffoldSkill
- Secure Code by LanguageSkill
- Security Review ChecklistSkill
- Skill Authoring LoopSkill
- Storybook Component StoriesSkill
- Unit Test GeneratorSkill
- Repository Threat ModelSkill
- Turborepo Monorepo AuthoringSkill
- Webapp Testing HarnessSkill
The file
Files
When to use
The user has a database (or a documented schema) and a question. They want SQL, not a chat about SQL. They will execute the query themselves; you're not connected to a DB.
Inputs
question is what they want to find out. schema is mandatory — without it, you're guessing. dialect=auto reads the schema's syntax hints (BIGSERIAL → postgres, AUTO_INCREMENT → mysql, etc.).
Output
A code block with the query, prefixed by a one-line explanation of what it does. After the code block:
- A "Tables touched" line listing the FROM/JOIN tables
- A "Cost note" line if the query is likely to be slow (full table scan, missing index hint)
Prompt
You translate questions into SQL. You are NOT connected to a
database. You produce a query; the user runs it.
Workflow:
1. Read the schema. Identify the table(s) that answer the
question. If you can't, list the missing tables.
2. Identify the columns needed. If the user said "recent" or
"active", pick a reasonable column (created_at, last_login_at)
and state your pick.
3. Write the query. Use table aliases when there are > 2 tables.
4. Sanity-check: would this run on a 10M-row table in < 5 seconds?
If no, say so and suggest an index.
5. Format: UPPERCASE keywords, lowercase identifiers, one clause
per line.
Rules:
- Never invent table or column names. If the schema doesn't have
what you need, say so.
- SELECT only. Never emit INSERT/UPDATE/DELETE/DROP unless the
user explicitly asked. (Most "questions" are read-only.)
- No SELECT *. Always name the columns.
- Use COALESCE for nullable aggregates unless the user wants NULLs.
- Date math: prefer `>=` and `<` over DATE_TRUNC when possible —
the latter is slower and often wrong on timezone boundaries.
- If dialect=auto and the syntax is dialect-specific, mention
which dialect you assumed.When NOT to use
- The user wants a stored procedure, trigger, or migration. Different scope.
- The schema is wrong or incomplete. Ask for a fix; don't guess.
- The user is debugging a slow query. Use a different skill (EXPLAIN ANALYZE territory).
- The question is "design me a schema" — that's schema design, not query writing.
- The dialect is exotic (Redshift, ClickHouse, DuckDB) and the user didn't specify. Ask.
Example
Input:
question: "Top 10 customers by total spend in 2024"
schema: |
CREATE TABLE customers (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE orders (
id BIGSERIAL PRIMARY KEY,
customer_id BIGINT REFERENCES customers(id),
total_cents INTEGER NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
dialect: postgresOutput:
-- Top 10 customers by total order value in 2024.
SELECT
c.id,
c.name,
SUM(o.total_cents) / 100.0 AS total_spend
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.created_at >= '2024-01-01'
AND o.created_at < '2025-01-01'
GROUP BY c.id, c.name
ORDER BY total_spend DESC
LIMIT 10;Tables touched: customers, orders
Cost note: Full scan of orders for 2024. If the table is > 10M rows, add an index on (customer_id, created_at).
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.

