sql-query
Generate and optimize SQL queries for data retrieval and analysis
When & Why to Use This Skill
This Claude skill streamlines database management and data analysis by generating, refining, and optimizing complex SQL queries. It empowers users to build high-performance queries—ranging from basic data retrieval to advanced window functions and multi-table joins—while ensuring adherence to security best practices and execution efficiency.
Use Cases
- Data Analysis & Reporting: Quickly generating complex SELECT statements involving aggregations and window functions for business intelligence reports.
- Performance Tuning: Refactoring inefficient legacy queries and using optimization strategies like indexing and EXPLAIN analysis to reduce database load.
- Database Operations: Safely constructing CRUD (Create, Read, Update, Delete) operations and complex subqueries for application development.
- Schema Integration: Building intricate JOIN logic across multiple tables to extract unified datasets for deep-dive research.
| name | sql-query |
|---|---|
| description | Generate and optimize SQL queries for data retrieval and analysis |
SQL Query
Generate SQL queries for data retrieval, analysis, and reporting.
Capabilities
- Generate SELECT, INSERT, UPDATE, DELETE queries
- Build complex JOINs and subqueries
- Aggregate data with GROUP BY and window functions
- Optimize query performance
Query Patterns
Basic Select
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1
LIMIT 100;
Aggregation
SELECT category, COUNT(*) as count, AVG(price) as avg_price
FROM products
GROUP BY category
HAVING COUNT(*) > 10;
Window Functions
SELECT
name,
department,
salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank
FROM employees;
Best Practices
- Always use parameterized queries to prevent SQL injection
- Index columns used in WHERE and JOIN clauses
- Avoid SELECT * in production queries
- Use EXPLAIN to analyze query performance