data-analytics-sql-reviewlisted
Install: claude install-skill alihusains/enterprise-skills
# Analytical SQL review
## Purpose
Analytical SQL fails quietly. A join fans out and the revenue total doubles; an
inner join drops the rows with no matching dimension and the count is 4% low; a
filter in the WHERE clause turns a left join into an inner one. None of these
raise an error, and all of them produce a number someone will act on. This skill
is the ordered checklist for those failure classes, plus the cost review that
stops a correct query from being unaffordable.
## Prerequisites
- **Inputs:** the query; the grain each source table is at (one row per what?);
expected row counts or an order of magnitude for the result; the metric
definition it implements.
- **Access:** ability to run the query's plan and row counts against a
representative dataset. Reviewing SQL by reading alone catches syntax and
obvious logic errors, but not fan-out — that needs counts.
If nobody can state the grain of each source table, establish that first. Almost
every fan-out and row-loss bug is a grain misunderstanding, and no amount of
reading the SQL surfaces it.
## Procedure
### Pass 1 — Correctness
1. **State the grain of every source and the intended grain of the output.**
Write it down as a sentence per table: "one row per order line", "one row per
customer per day". Then check every join: joining a one-row-per-customer table
to a one-row-per-order table produces one row per order — if an aggregate
downstream sums a customer-level column, it is now multiplied