SQL Writing and Optimization

VerifiedSafe

Helps write, optimize, or explain SQL queries. Looks for issues like missing indexes, N+1 patterns, unnecessary SELECT *, and suggests improvements. Best used when you need to generate clean SQL or troubleshoot query performance.

Sby Skills Guide Bot
Data & AIIntermediate
1206/2/2026
Claude CodeCursorWindsurfCopilotCodex
#sql#database#query-optimization#data-analysis

Recommended for

Our review

Helps write, optimize, or explain SQL queries with clarity and best practices.

Strengths

  • Produces clean, readable SQL with proper formatting and CTEs
  • Detects performance issues like missing indexes or N+1 queries
  • Explains queries step-by-step

Limitations

  • Requires database type specification for database-specific optimizations
  • Cannot tune database server configuration
When to use it

When you need to write a complex query, optimize a slow one, or understand an unfamiliar SQL statement.

When not to use it

For reporting tool-specific queries that rely on proprietary functions (Power BI, Tableau).

Security analysis

Safe
Quality score85/100

The skill only provides guidance on writing, optimizing, and explaining SQL queries, with no executable actions or dangerous instructions.

No concerns found

Examples

Write a SQL query for monthly sales
Write a SQL query to calculate total sales per month for the last year, including product category breakdown. Use PostgreSQL syntax.
Optimize a slow query
Optimize this query: SELECT * FROM orders WHERE customer_id IN (SELECT id FROM customers WHERE signup_date > '2020-01-01') ORDER BY created_at;
Explain a complex SQL query
Explain this SQL step by step: SELECT department, avg(salary) OVER (PARTITION BY department) as dept_avg, salary - avg(salary) OVER (PARTITION BY department) as diff FROM employees;

name: sql description: This skill should be used when the user asks to "write SQL", "optimize a query", "explain this SQL", or needs help with database queries and SQL best practices.

/sql

Help write, optimize, or explain SQL queries.

Instructions

When the user provides a SQL query or describes what they need:

  1. Writing SQL: Generate clean, readable SQL with:

    • Proper indentation and capitalization
    • CTEs over nested subqueries when complex
    • Comments for non-obvious logic
  2. Optimizing SQL: Look for:

    • Missing indexes (suggest based on WHERE/JOIN columns)
    • N+1 patterns
    • Unnecessary SELECT *
    • Subqueries that could be JOINs
    • Opportunities for window functions
  3. Explaining SQL: Break down the query step by step, explaining what each part does

Ask for the database type (PostgreSQL, MySQL, BigQuery, etc.) if not specified.

Related skills