sql-root-cause-analysis

sql-root-cause-analysis is a skill for Claude Code, Codex from zj-unicom-ai/UniEmployee. It costs 47 tokens per session (1,130 once invoked), scanned A, original, MIT.

A SQL-based method for finding why a business metric changed, such as revenue, orders, conversion, or cost. SQL is a language for querying data in databases; the method compares periods and breaks changes down by dimensions such as region, product, and channel.

In plain words
What is it for?
It is for investigating increases, declines, anomalies, and KPI shortfalls using database searches, table relationships, quality checks, and cause breakdowns.
Why use it?
It replaces guesswork about trends or missed targets with checked data, contribution calculations, and explicit limits when the data is incomplete.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It is for investigating increases, declines, anomalies, and KPI shortfalls using database searches, table relationships, quality checks, and cause breakdowns.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis
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.

Any agent
npx skills add zj-unicom-ai/UniEmployee --skill sql-root-cause-analysis
Clone the repo
git clone --depth 1 https://github.com/zj-unicom-ai/UniEmployee

Made for: Claude Code, Codex.

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 sql-root-cause-analysis

README.md
[![agentmods](https://agentmods.dev/badge/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis/github.svg)](https://agentmods.dev/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis)
Your own site
<a href="https://agentmods.dev/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis"><img src="https://agentmods.dev/badge/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for sql-root-cause-analysis

Your own site · 80×15
<a href="https://agentmods.dev/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis"><img src="https://agentmods.dev/badge/skills/zj-unicom-ai/uniemployee/sql-root-cause-analysis.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 47 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,130 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00047 $0.01130
Opus 5.5 $0.00019 $0.00452
Sonnet 5.5 $0.00009 $0.00226
Haiku 4.5 $0.00005 $0.00113

Measured 29d ago against content hash a1d9a1c5d743, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

sql-root-cause-analysis 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 29d 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.

backend/skills/sql-root-cause-analysis/SKILL.md · 97 lines

What it actually says

SQL 版归因分析

你是数据分析师。遇到“为什么”“下降原因”“增长来自哪里”“异常波动”“KPI 未达标”等问题时,必须按本规程做归因分析。只使用小数可用的 SQL / 表格 / 知识库 / 连接器工具,禁止使用 run_python、文件系统和本地脚本。

适用范围

  • 营收、订单量、利润、转化率、复购率、客单价等指标明显变化
  • 某地区、产品、渠道、客户分群表现显著偏离整体
  • 用户明确问“为什么”“原因”“归因”“拖累项”“拉动项”
  • 用户要求复盘、诊断、波动分析、KPI 未达标分析

执行步骤

步骤 1:确认问题口径

先从用户问题中识别:

  • 目标指标:例如销售额、订单数、客单价、转化率
  • 目标周期:例如本月、上月、最近 7 天、某季度
  • 对比基准:环比、同比、目标值、整体平均、其他分组
  • 可下钻维度:时间、地区、产品、渠道、客户、销售等

口径不清但可合理假设时,先说明假设后继续;缺少关键字段时,先检索 schema 再判断。

步骤 2:获取并验证数据

  1. 调用 sql_db_smart_search(user_query="用户原始问题") 获取相关表结构。
  2. 涉及多表时调用 sql_db_table_relationship(table_names="...")。
  3. 对核心表调用 sql_db_profile(table_names="..."),确认行数、字段非空率、时间范围和数值范围。
  4. 核心分析 SQL 执行后调用 sql_db_quality_check(query="核心 SQL")。如果样本量小、缺失多或结果为空,后续结论必须降级。

步骤 3:确认异常事实

先跑总览 SQL,确认异常是否真实存在:

  • 当前周期指标值
  • 对比周期指标值
  • 变化量 = 当前值 - 对比值
  • 变化率 = 变化量 / 对比值

如果异常不存在,直接说明“当前数据不支持异常判断”,不要继续编造原因。

步骤 4:维度贡献拆解

对每个可用维度分别计算:

  • 当前周期值
  • 对比周期值
  • 变化量
  • 变化率
  • 对总体变化的贡献度

优先下钻这些维度:

  1. 时间:找到变化发生在哪一天/周/月
  2. 地区:定位主要拖累或拉动区域
  3. 产品:定位主要拖累或拉动品类/SKU
  4. 渠道:定位渠道结构变化
  5. 客户:定位头部客户、客户分群或新老客变化

贡献度公式:

维度项变化量 / 总体变化量

总体变化量为 0 时,不计算贡献度,改用当前值占比和变化率解释。

步骤 5:量价/结构拆解

当指标是收入、销售额、GMV 等金额类指标时,尽量拆成:

  • 量:订单数、销量、客户数
  • 价:客单价、件均价、折扣率
  • 结构:高低价产品占比、渠道占比、客户结构变化

判断方向:

  • 订单数下降:优先看需求、流量、渠道、客户流失
  • 客单价下降:优先看折扣、产品结构、低价品占比
  • 转化率下降:优先看流量质量、渠道、人群和关键漏斗环节
  • 成本上升:优先看用量、单价、供应商/区域/产品结构

步骤 6:形成归因结论

输出必须包含四段:

  1. 异常定位:哪个指标、哪个周期、变化多少
  2. 主要归因:贡献最大的 2-4 个维度项,必须带数字
  3. 证据强度:说明是“数据直接支持”“高度相关”“需要补充数据验证”
  4. 建议动作:短期排查、业务动作、后续补数方向

输出原则

  • 结论先行,但不要跳过数据验证
  • 每个原因都必须有数字支撑
  • 避免单一归因,复杂经营波动通常是多因素叠加
  • 不要把相关性写成确定因果;证据不足时用“可能”“需要验证”
  • 如果数据质量不支持归因,要明确说“不足以归因”,并列出需要补充的数据
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. 29d ago First seen · 97 lines · 47 tokens per session scan A a1d9a1c5d743

Subscribe to this mod's changes

sql-root-cause-analysis is a skill published in the GitHub repository zj-unicom-ai/UniEmployee (362 stars, last pushed 8d ago), licensed MIT. It adds 47 tokens to every session and 1,130 once invoked, about $0.0002 per session on Opus 5.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-09-17.

Related

Other skills, from other repositories

data-to-ontology-mapping-and-instantiation

A mapping process that connects records and fields from confirmed data sources to classes, properties, relationships, and instances in an approved ontology. An instance is a concrete example of a modeled thing, such as one customer or order.

SuperChason/ontology-driven-ai-data-management-skills · 106 tokens

omnigraph

Operate OmniGraph graphs and deployments. Use for .pg schemas, .gq queries, OmniGraph CLI commands, file:///s3:///az:// graph URIs, cluster.yaml, operator config, bearer-authenticated servers, graph-backed knowledge or memory, Blob values, embeddings, branches, commits, and change feeds. Apply especially before schema…

ModernRelay/omnigraph · 94 tokens

hugegraph-regression-tester

Route HugeGraph MCP regression testing tasks to the current public tool surface, including inspection, read-only queries, Gremlin generation, extraction, controlled import, schema validate/dry-run, safety guards, and admin-gated tool checks.

apache/hugegraph-ai · 54 tokens

hugegraph-data-importer

Route HugeGraph MCP graph data extraction and controlled import/delete tasks to stable public tools. Use when the user asks to extract graph data from text, import structured vertices or edges, verify an import, or asks whether table, SQL, update, or delete graph writes are available.

apache/hugegraph-ai · 62 tokens

hugegraph-schema-designer

Route HugeGraph MCP schema design, validation, and dry-run preview tasks to stable public tools. Use when the user asks to design vertex labels, edge labels, properties, primary keys, indexes, or preview schema operations.

apache/hugegraph-ai · 51 tokens

fetch-data

A workflow that turns a plain-language request for business data into a database query, runs it in a data warehouse or lake, and returns the results for analysis.

agentscope-ai/QwenPaw-Data · 276 tokens