Imported from MMostafa-Hub/deep-analytics-agent (
skills/sql-analytics/SKILL.md). Install upstream withnpx skills add MMostafa-Hub/deep-analytics-agent --skill sql-analytics. Copyright stays with the author.
SQL Analytics Skill
Tool
query — executes a single read-only SQL SELECT. Always inspect the live schema first.
General patterns
Aggregation with grouping
SELECT <dimension>, SUM(<measure>) AS total
FROM <table>
JOIN <other> ON <join_condition>
WHERE <filters>
GROUP BY <dimension>
ORDER BY total DESC
LIMIT 20;
Time-series bucketing
SELECT DATE_TRUNC('month', <date_column>) AS period,
SUM(<measure>) AS value
FROM <table>
WHERE <date_column> >= NOW() - INTERVAL '12 months'
GROUP BY 1
ORDER BY 1;
Joining multiple tables
SELECT a.<col>, b.<col>, c.<col>
FROM <table_a> a
JOIN <table_b> b ON a.id = b.a_id
LEFT JOIN <table_c> c ON b.id = c.b_id
WHERE <conditions>;
Rules
- Only SELECT — no INSERT/UPDATE/DELETE/DDL
- Qualify column names with table aliases when joining to avoid ambiguity
- Use
LIMITunless the user explicitly wants all rows - For percentages:
ROUND(100.0 * numerator / NULLIF(denominator, 0), 2)