write-query

write-query is a command for coding agents from killvxk/pm-skills-zh. It costs 22 tokens per session (750 once invoked), scanned A, original, MIT.

A natural-language tool that turns a plain request into SQL, the language used to retrieve data from databases. It supports database formats including BigQuery, PostgreSQL, and MySQL.

In plain words
What is it for?
Use it to create commented queries for metrics, filtering, grouping, rankings, and cohort analysis, using a supplied database structure when available.
Why use it?
It removes the need to write every query from scratch and makes assumptions about tables, fields, filters, and edge cases visible for review.

Command

Part of the pm-data-analytics plugin — 3 skills, 3 commands shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/killvxk/pm-skills-zh/write-query
Clone the repo
git clone --depth 1 https://github.com/killvxk/pm-skills-zh

Or install pm-data-analytics, the plugin that ships this one along with the rest of its 3 skills, 3 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for write-query

README.md
[![agentmods](https://agentmods.dev/badge/commands/killvxk/pm-skills-zh/write-query.svg)](https://agentmods.dev/commands/killvxk/pm-skills-zh/write-query)
Your own site
<a href="https://agentmods.dev/commands/killvxk/pm-skills-zh/write-query"><img src="https://agentmods.dev/badge/commands/killvxk/pm-skills-zh/write-query.svg" alt="Measured on agentmods" height="20"></a>
Per session 22 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 750 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00022 $0.00750
Opus 5 $0.00011 $0.00375
Sonnet 5 $0.00004 $0.00150
Haiku 4.5 $0.00002 $0.00075

Measured 4d ago against content hash 8420fefb5197, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

write-query scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

pm-data-analytics/commands/write-query.md · 85 lines

What it actually says

/write-query -- SQL 查询生成器

用自然语言描述你需要的数据,即可获得经过优化的 SQL 查询。支持多种数据库方言,也可读取上传文件中的数据库结构。

调用方式

/write-query 查看过去 30 天的每日活跃用户数,按套餐等级分组
/write-query 找出上个月注册但从未完成新手引导的用户
/write-query [上传数据库结构图] 按同期群统计试用转付费的转化率是多少?

工作流程

第一步:理解需求

解析用户的自然语言请求,识别:

  • 需要查询的数据(指标、维度、过滤条件)
  • 时间范围与时间粒度
  • 分组和排序偏好
  • 输出形式(原始数据、聚合数据、排名)

第二步:确认数据库结构

如果有可用的结构信息(上传的结构图、DDL 或文字描述):

  • 将请求映射到具体的表和字段
  • 识别所需的关联关系

如果没有提供结构信息:

  • 询问数据库类型(BigQuery、PostgreSQL、MySQL 等)
  • 根据问题推断合理的数据库结构,并请用户确认
  • 以常见 SaaS 数据模型惯例作为默认假设

第三步:生成查询

应用 sql-queries 技能:

  • 使用正确的方言编写 SQL 查询
  • 兼顾可读性和执行性能进行优化
  • 添加注释,解释关键逻辑
  • 对于复杂查询,使用 CTE(公共表表达式)提升可读性
  • 处理边界情况(NULL 值、时区处理、去重逻辑)

第四步:呈现结果并迭代

## SQL 查询:[查询说明]

**方言**:[BigQuery / PostgreSQL / MySQL / 其他]
**涉及的表**:[列表]

### 查询语句
[带注释的 SQL 代码块]

### 返回结果说明
[输出内容描述:字段、行数、预期结果形态]

### 假设条件
- [关于数据库结构的假设]
- [关于业务逻辑的假设]

### 备注
- [大数据集的性能注意事项]
- [已处理或已标记的边界情况]

后续可提供:

  • "要我修改这个查询——增加过滤条件、调整分组或延长时间范围吗?"
  • "要我生成一个配套查询来查看相关指标吗?"
  • "要我围绕这个查询搭建一个数据看板吗?"
  • "需要这个数据的同期群分析版本吗?"

注意事项

  • SQL 中始终加注释——产品经理会把查询分享给分析师,对方需要理解查询意图
  • 优先选择可读性强的写法,而非炫技——用 CTE 而非嵌套子查询
  • 标记可能在大数据集上运行缓慢的查询,并提供优化建议
  • 如果需求模糊(例如"活跃用户"),请用户明确定义该指标
  • 如果用户不确定使用的是哪个数据库,可以提供多种方言版本
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 85 lines · 22 tokens per session scan A 8420fefb5197

Subscribe to this mod's changes

write-query is a command published in the GitHub repository killvxk/pm-skills-zh (151 stars, last pushed 5mo ago), licensed MIT. It adds 22 tokens to every session and 750 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.