query-writing

当您需要通过编写和执行 SQL 查询来回答问题时应使用此技能。

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "query-writing" with this command: npx skills add apconw/aix-db/apconw-aix-db-query-writing

查询编写技能

何时使用此技能

当您需要通过编写和执行 SQL 查询来回答问题时应使用此技能。

简单查询工作流程

对于涉及单个表的直接问题:

  • 识别表 - 哪个表包含所需数据?

  • 获取架构 - 使用 sql_db_schema 查看列

  • 编写查询 - 使用 WHERE/LIMIT/ORDER BY 选择相关列

  • 执行 - 使用 sql_db_query 运行

  • 格式化答案 - 清晰地呈现结果

复杂查询工作流程

对于需要多个表的问题:

  1. 规划方法

使用 write_todos 分解任务:

  • 识别所有需要的表

  • 映射关系(外键)

  • 规划 JOIN 结构

  • 确定聚合操作

  1. 检查架构

对每个表使用 sql_db_schema 查找连接列和所需字段。

  1. 构建查询
  • SELECT - 列和聚合函数

  • FROM/JOIN - 通过 FK = PK 连接表

  • WHERE - 聚合前的过滤条件

  • GROUP BY - 所有非聚合列

  • ORDER BY - 有意义的排序

  • LIMIT - 默认 5 行

  1. 验证和执行

检查所有 JOIN 都有条件,GROUP BY 正确,然后运行查询。

示例:按国家统计收入

SELECT c.Country, ROUND(SUM(i.Total), 2) as TotalRevenue FROM Invoice i INNER JOIN Customer c ON i.CustomerId = c.CustomerId GROUP BY c.Country ORDER BY TotalRevenue DESC LIMIT 5;

质量指南

  • 只查询相关列(不使用 SELECT *)

  • 始终应用 LIMIT(默认 10)

  • 使用表别名以提高清晰度

  • 对于复杂查询:使用 write_todos 进行规划

  • 绝不使用 DML 语句(INSERT, UPDATE, DELETE, DROP)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

ui-ux-pro-max

No summary provided by upstream source.

Repository SourceNeeds Review
General

report-generation

No summary provided by upstream source.

Repository SourceNeeds Review
Web3

query-writing

No summary provided by upstream source.

Repository SourceNeeds Review
General

image-gen

Generate AI images from text prompts. Triggers on: "生成图片", "画一张", "AI图", "generate image", "配图", "create picture", "draw", "visualize", "generate an image".

Archived SourceRecently Updated