sql-pro by 404kidwiz/claude-supercode-skills
npx skills add https://github.com/404kidwiz/claude-supercode-skills --skill sql-pro提供跨主流数据库平台(PostgreSQL、MySQL、SQL Server、Oracle)的专业 SQL 开发能力,专注于复杂查询设计、性能优化和数据库架构。精通 ANSI SQL 标准、平台特定的优化以及现代数据模式,注重效率和可扩展性。
在以下情况调用此技能:
在以下情况不要调用:
Query Requirement Analysis
│
├─ Need to reference result multiple times?
│ └─ YES → Use CTE (avoids duplicate subquery evaluation)
│ WITH user_totals AS (SELECT ...)
│ SELECT * FROM user_totals WHERE ...
│ UNION ALL
│ SELECT * FROM user_totals WHERE ...
│
├─ Recursive data traversal (hierarchy, graph)?
│ └─ YES → Use Recursive CTE (ONLY option for recursion)
│ WITH RECURSIVE tree AS (
│ SELECT ... -- anchor
│ UNION ALL
│ SELECT ... FROM tree ... -- recursive
│ )
│
├─ Simple lookup or filter?
│ └─ Use JOIN (most optimizable by query planner)
│ SELECT u.*, o.total
│ FROM users u
│ JOIN orders o ON u.id = o.user_id
│
├─ Correlated subquery in WHERE clause?
│ ├─ Checking existence → Use EXISTS (stops at first match)
│ │ WHERE EXISTS (SELECT 1 FROM orders WHERE user_id = u.id)
│ │
│ └─ Value comparison → Use JOIN instead
│ -- BAD: WHERE (SELECT COUNT(*) FROM orders WHERE user_id = users.id) > 5
│ -- GOOD: JOIN (SELECT user_id, COUNT(*) as cnt FROM orders GROUP BY user_id)
│
└─ Readability vs Performance trade-off?
├─ Complex logic, readability critical → CTE
│ (Easier to understand, debug, maintain)
│
└─ Performance critical, simple logic → Subquery or JOIN
(Query planner can inline and optimize)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 需求 | 解决方案 | 示例 |
|---|---|---|
| 需要聚合 + 行级详细信息 | 窗口函数 | SELECT name, salary, AVG(salary) OVER () as avg_salary FROM employees |
| 仅需要聚合结果 | GROUP BY | SELECT dept, AVG(salary) FROM employees GROUP BY dept |
| 排名/行号 | 窗口函数 (ROW_NUMBER, RANK, DENSE_RANK) | ROW_NUMBER() OVER (ORDER BY sales DESC) |
| 累计总计 / 移动平均 | 带框架的窗口函数 | SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) |
| LAG/LEAD(访问前/后行) | 窗口函数 | LAG(price, 1) OVER (ORDER BY date) as prev_price |
| 百分位数 / NTILE | 窗口函数 | NTILE(4) OVER (ORDER BY score) as quartile |
| 按组进行简单计数/求和/平均 | GROUP BY(更高效) | SELECT category, COUNT(*) FROM products GROUP BY category |
| 观察现象 | 升级原因 | 示例 |
|---|---|---|
| 执行计划中出现笛卡尔积 | 意外的交叉连接导致行数指数级增长 | "查询返回数百万行" |
| 复杂的多级递归 CTE 性能问题 | 需要高级优化 | "递归 CTE 遍历 10+ 层,包含 100K 个节点" |
| 具有不兼容功能的跨平台迁移 | 平台特定功能映射 | "将 Oracle CONNECT BY 迁移到 PostgreSQL 递归 CTE" |
| 包含 10+ 个连接和复杂逻辑的查询 | 架构异味,可能需要重新设计 | "连接 15 个表的单个查询" |
| 具有复杂时间序列逻辑的时间查询 | 高级分析模式 | "带有历史快照的 SCD 类型 2" |
查询性能:
SQL 质量:
优化:
文档:
每周安装次数
62
代码仓库
GitHub 星标数
45
首次出现
2026年1月24日
安全审计
安装于
opencode50
claude-code47
gemini-cli46
codex46
cursor43
github-copilot39
Provides expert SQL development capabilities across major database platforms (PostgreSQL, MySQL, SQL Server, Oracle), specializing in complex query design, performance optimization, and database architecture. Masters ANSI SQL standards, platform-specific optimizations, and modern data patterns with focus on efficiency and scalability.
Invoke this skill when:
Do NOT invoke when:
Query Requirement Analysis
│
├─ Need to reference result multiple times?
│ └─ YES → Use CTE (avoids duplicate subquery evaluation)
│ WITH user_totals AS (SELECT ...)
│ SELECT * FROM user_totals WHERE ...
│ UNION ALL
│ SELECT * FROM user_totals WHERE ...
│
├─ Recursive data traversal (hierarchy, graph)?
│ └─ YES → Use Recursive CTE (ONLY option for recursion)
│ WITH RECURSIVE tree AS (
│ SELECT ... -- anchor
│ UNION ALL
│ SELECT ... FROM tree ... -- recursive
│ )
│
├─ Simple lookup or filter?
│ └─ Use JOIN (most optimizable by query planner)
│ SELECT u.*, o.total
│ FROM users u
│ JOIN orders o ON u.id = o.user_id
│
├─ Correlated subquery in WHERE clause?
│ ├─ Checking existence → Use EXISTS (stops at first match)
│ │ WHERE EXISTS (SELECT 1 FROM orders WHERE user_id = u.id)
│ │
│ └─ Value comparison → Use JOIN instead
│ -- BAD: WHERE (SELECT COUNT(*) FROM orders WHERE user_id = users.id) > 5
│ -- GOOD: JOIN (SELECT user_id, COUNT(*) as cnt FROM orders GROUP BY user_id)
│
└─ Readability vs Performance trade-off?
├─ Complex logic, readability critical → CTE
│ (Easier to understand, debug, maintain)
│
└─ Performance critical, simple logic → Subquery or JOIN
(Query planner can inline and optimize)
| Requirement | Solution | Example |
|---|---|---|
| Need aggregation + row-level detail | Window function | SELECT name, salary, AVG(salary) OVER () as avg_salary FROM employees |
| Only aggregated results needed | GROUP BY | SELECT dept, AVG(salary) FROM employees GROUP BY dept |
| Ranking/row numbering | Window function (ROW_NUMBER, RANK, DENSE_RANK) | ROW_NUMBER() OVER (ORDER BY sales DESC) |
| Running totals / moving averages | Window function with frame | SUM(amount) OVER (ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) |
| Observation | Why Escalate | Example |
|---|---|---|
| Cartesian product in execution plan | Unintended cross join causing exponential rows | "Query returning millions of rows" |
| Complex multi-level recursive CTE performance | Advanced optimization needed | "Recursive CTE traversing 10+ levels with 100K nodes" |
| Cross-platform migration with incompatible features | Platform-specific feature mapping | "Migrating Oracle CONNECT BY to PostgreSQL recursive CTE" |
| Query with 10+ joins and complex logic | Architecture smell, potential redesign | "Single query joining 15 tables" |
| Temporal query with complex time-series logic | Advanced analytical pattern | "SCD Type 2 with historical snapshots" |
Query Performance:
SQL Quality:
Optimization:
Documentation:
Weekly Installs
62
Repository
GitHub Stars
45
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode50
claude-code47
gemini-cli46
codex46
cursor43
github-copilot39
Supabase 使用指南:安全最佳实践、CLI 命令与 MCP 服务器配置
3,600 周安装
| LAG/LEAD (access previous/next rows) | Window function | LAG(price, 1) OVER (ORDER BY date) as prev_price |
| Percentile / NTILE | Window function | NTILE(4) OVER (ORDER BY score) as quartile |
| Simple count/sum/avg by group | GROUP BY (more efficient) | SELECT category, COUNT(*) FROM products GROUP BY category |