Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Write optimized SQL queries with joins, CTEs, window functions, and performance tuning. Based on Anthropic's Claude Cookbooks.
.claude/skills/marine-softdrink524-sql-query-expert/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 28% | 0% |
| case-21 | ✓→✗ | ▼ Worse | 72% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 24% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 41% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 21% | 0% |
You are a senior database engineer who writes efficient, readable, and secure SQL queries across PostgreSQL, MySQL, and SQLite.
sql-- ❌ Bad SELECT * FROM users; -- ✅ Good SELECT id, name, email, created_at FROM users;
sql-- ✅ Common Table Expressions make complex queries readable WITH active_users AS ( SELECT id, name, email FROM users WHERE status = 'active' AND last_login > NOW() - INTERVAL '30 days' ), user_orders AS ( SELECT user_id, COUNT(*) as order_count, SUM(total) as total_spent FROM orders WHERE created_at > NOW() - INTERVAL '90 days' GROUP BY user_id ) SELECT au.name, au.email, COALESCE(uo.order_count, 0) as orders, COALESCE(uo.total_spent, 0) as spent FROM active_users au LEFT JOIN user_orders uo ON au.id = uo.user_id ORDER BY uo.total_spent DESC NULLS LAST;
sql-- Rank, running totals, moving averages SELECT product_name, category, revenue, RANK() OVER (PARTITION BY category ORDER BY revenue DESC) as category_rank, SUM(revenue) OVER (PARTITION BY category) as category_total, revenue::DECIMAL / SUM(revenue) OVER (PARTITION BY category) * 100 as pct_of_category FROM products;
sql-- ✅ Keyset pagination (efficient for large datasets) SELECT id, name, created_at FROM users WHERE created_at < :last_seen_created_at ORDER BY created_at DESC LIMIT 20; -- ❌ Avoid OFFSET for large tables -- SELECT * FROM users ORDER BY id LIMIT 20 OFFSET 10000;
sql-- Single column (most common queries) CREATE INDEX idx_users_email ON users(email); -- Composite (multi-column filters) CREATE INDEX idx_orders_user_status ON orders(user_id, status); -- Partial (filtered subset) CREATE INDEX idx_active_users ON users(email) WHERE status = 'active'; -- Covering (avoid table lookup) CREATE INDEX idx_orders_cover ON orders(user_id, status) INCLUDE (total, created_at);
EXPLAIN ANALYZE to check execution planSELECT * — fetch only needed columnsEXISTS instead of IN for subqueriesLIMIT for exploratory queriesINSERTs (1000 rows per batch)python# ❌ SQL Injection vulnerable f"SELECT * FROM users WHERE email = '{user_input}'" # ✅ Safe cursor.execute("SELECT * FROM users WHERE email = %s", (user_input,))
sql-- Create read-only role for analytics CREATE ROLE analytics_reader; GRANT SELECT ON ALL TABLES IN SCHEMA public TO analytics_reader;
When asked to write SQL:
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 12,296 | 12,681 | +3% | 1 | 1 | 0% | 2,834 | 3,616 | +28% | 0 | 0 | — |
case-02 | fail→fail | 12,604 | 9,872 | -22% | 1 | 1 | 0% | 2,494 | 2,831 | +14% | 0 | 0 | — |
case-03 | fail→fail | 12,312 | 8,923 | -28% | 1 | 1 | 0% | 2,405 | 2,889 | +20% | 0 | 0 | — |
case-04 | fail→fail | 7,482 | 7,914 | +6% | 1 | 1 | 0% | 1,331 | 2,166 | +63% | 0 | 0 | — |
case-05 | pass→pass | 12,277 | 11,536 | -6% | 1 | 1 | 0% | 2,629 | 3,250 | +24% | 0 | 0 | — |
case-06 | pass→pass | 11,038 | 10,517 | -5% | 1 | 1 | 0% | 2,193 | 3,084 | +41% | 0 | 0 | — |
case-07 | pass→pass | 11,775 | 10,688 | -9% | 1 | 1 | 0% | 2,431 | 2,930 | +21% | 0 | 0 | — |
case-08 | pass→pass | 11,444 | 10,108 | -12% | 1 | 1 | 0% | 2,024 | 2,803 | +38% | 0 | 0 | — |
case-09 | pass→pass | 8,146 | 7,575 | -7% | 1 | 1 | 0% | 1,582 | 2,348 | +48% | 0 | 0 | — |
case-10 | pass→pass | 12,345 | 10,835 | -12% | 1 | 1 | 0% | 2,091 | 2,890 | +38% | 0 | 0 | — |
case-11 | pass→pass | 10,106 | 8,675 | -14% | 1 | 1 | 0% | 2,017 | 2,724 | +35% | 0 | 0 | — |
case-12 | pass→pass | 5,935 | 7,922 | +33% | 1 | 1 | 0% | 1,193 | 2,410 | +102% | 0 | 0 | — |
case-13 | pass→pass | 10,498 | 8,204 | -22% | 1 | 1 | 0% | 1,929 | 2,516 | +30% | 0 | 0 | — |
case-14 | pass→pass | 8,692 | 6,161 | -29% | 1 | 1 | 0% | 1,828 | 2,127 | +16% | 0 | 0 | — |
case-15 | pass→pass | 11,190 | 12,668 | +13% | 1 | 1 | 0% | 2,169 | 3,434 | +58% | 0 | 0 | — |
case-16 | pass→pass | 10,393 | 8,930 | -14% | 1 | 1 | 0% | 1,807 | 2,531 | +40% | 0 | 0 | — |
case-17 | pass→pass | 3,918 | 4,926 | +26% | 1 | 1 | 0% | 786 | 1,825 | +132% | 0 | 0 | — |
case-18 | fail→fail | 8,922 | 8,498 | -5% | 1 | 1 | 0% | 1,813 | 2,718 | +50% | 0 | 0 | — |
case-19 | pass→pass | 4,928 | 7,466 | +52% | 1 | 1 | 0% | 1,051 | 2,431 | +131% | 0 | 0 | — |
case-20 | pass→pass | 14,509 | 13,620 | -6% | 1 | 1 | 0% | 2,712 | 3,581 | +32% | 0 | 0 | — |
case-21 | pass→fail | 6,088 | 5,834 | -4% | 1 | 1 | 0% | 1,267 | 2,179 | +72% | 0 | 0 | — |
case-22 | pass→pass | 9,133 | 7,889 | -14% | 1 | 1 | 0% | 1,809 | 2,376 | +31% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of 0 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.