📘

SQL Analysis

Query data correctly.

v1 data curated
🤖

Install 安装

curl -sSL https://updating.cc/skills/data/sql-analysis/SKILL.md -o ~/.agents/skills/data__sql-analysis/SKILL.md

SKILL.md Preview 技能内容预览

---
name: SQL Analysis
description: Query data correctly.
---
# SQL Analysis

Most analytical errors are query errors: wrong joins, hidden duplicates, mismatched grains. Write SQL defensively and check intermediate results.

## Habits
- **Inspect each step.** `SELECT ...` the subquery before nesting it. Row counts before and after a join catch fan-out from one-to-many relationships.
- **Know your grain.** What does one row represent? A JOIN that changes the row count has changed the grain, and your aggregates with it.
- **LEFT vs INNER deliberately.** INNER drops unmatched rows silently; LEFT preserves them. Mismatched choice is a common silent bug.
- **Window functions for "top N per group".** `ROW_NUMBER() OVER (PARTITION BY user ORDER BY date DESC)` beats self-joins.
- **Validate totals.** Does the sum of your query match a known total? If not, you've filtered or joined something wrong.