Provides advanced SQL analytics patterns: window functions (ROW_NUMBER, RANK, LAG, LEAD), recursive CTEs, pivots, and query optimization. Activates on analytical queries or window function keywords.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
EXPLAIN ANALYZE (PG) / SET STATISTICS IO ON (SQL Server).| Besoin | Fonction |
|---|---|
| Rang sans ex-aequo | ROW_NUMBER() |
| Rang avec ex-aequo, sauts | RANK() |
| Rang avec ex-aequo, continu | DENSE_RANK() |
| Découper en N groupes égaux | NTILE(N) |
| Valeur N lignes avant/après | LAG(col, N) / LEAD(col, N) |
| Cumul depuis le début | SUM() OVER (ORDER BY ... ROWS UNBOUNDED PRECEDING) |
| Moyenne mobile | AVG() OVER (ROWS BETWEEN N PRECEDING AND CURRENT ROW) |
| Premier/dernier de la partition | FIRST_VALUE() / LAST_VALUE() + frame explicite |
SELECT
product_name,
category,
total_sales,
ROW_NUMBER() OVER (PARTITION BY category ORDER BY total_sales DESC) AS rn,
RANK() OVER (PARTITION BY category ORDER BY total_sales DESC) AS rnk,
DENSE_RANK() OVER (PARTITION BY category ORDER BY total_sales DESC) AS dense_rnk,
NTILE(4) OVER (PARTITION BY category ORDER BY total_sales DESC) AS quartile
FROM products;
SELECT
month,
revenue,
LAG(revenue, 1) OVER (ORDER BY month) AS prev_month,
revenue - LAG(revenue, 1) OVER (ORDER BY month) AS mom_delta,
LEAD(revenue, 1) OVER (ORDER BY month) AS next_month,
AVG(revenue) OVER (ORDER BY month ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS ma_3m,
SUM(revenue) OVER (ORDER BY month ROWS UNBOUNDED PRECEDING) AS cumul
FROM monthly_sales;
-- Sans "ROWS UNBOUNDED FOLLOWING", LAST_VALUE retourne la ligne courante, pas la dernière !
SELECT DISTINCT
customer_id,
FIRST_VALUE(product_name) OVER w AS first_purchase,
LAST_VALUE(product_name) OVER w AS last_purchase
FROM orders
WINDOW w AS (
PARTITION BY customer_id ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
);
-- Garder la ligne la plus récente par customer_id
WITH ranked AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY updated_at DESC) AS rn
FROM orders
)
SELECT * FROM ranked WHERE rn = 1;
WITH
revenue_by_month AS (
SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS revenue
FROM orders
GROUP BY 1
),
ranked AS (
SELECT *, RANK() OVER (ORDER BY revenue DESC) AS rnk
FROM revenue_by_month
)
SELECT * FROM ranked WHERE rnk <= 5;
WITH RECURSIVE org_tree AS (
-- Ancre : nœud racine
SELECT id, name, manager_id, 1 AS depth, CAST(name AS TEXT) AS path
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Récursion
SELECT e.id, e.name, e.manager_id, ot.depth + 1, ot.path || ' > ' || e.name
FROM employees e
JOIN org_tree ot ON e.manager_id = ot.id
WHERE ot.depth < 10 -- garde-fou anti-cycle
)
SELECT * FROM org_tree ORDER BY path;
SELECT
product_name,
SUM(CASE WHEN EXTRACT(MONTH FROM sale_date) = 1 THEN amount ELSE 0 END) AS jan,
SUM(CASE WHEN EXTRACT(MONTH FROM sale_date) = 2 THEN amount ELSE 0 END) AS feb,
SUM(CASE WHEN EXTRACT(MONTH FROM sale_date) = 3 THEN amount ELSE 0 END) AS mar
FROM sales
GROUP BY product_name;
SELECT product_name, [1] AS jan, [2] AS feb, [3] AS mar
FROM (
SELECT product_name, MONTH(sale_date) AS m, amount FROM sales
) src
PIVOT (SUM(amount) FOR m IN ([1],[2],[3])) pvt;
SELECT product_name, month_name, revenue
FROM monthly_pivot
UNPIVOT (revenue FOR month_name IN (jan, feb, mar)) u;
-- PostgreSQL
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) <votre requête>;
-- SQL Server
SET STATISTICS IO ON;
SET STATISTICS TIME ON;
-- puis exécuter la requête, lire "logical reads"
Signaux d'alarme : Hash Join sur très grandes tables, Sort sur colonnes non indexées, Nested Loop avec Index Scan répété.
-- Couvre PARTITION BY + ORDER BY + colonnes SELECT
CREATE INDEX idx_sales_analytics
ON sales (category, sale_date)
INCLUDE (amount, product_id);
-- Index partiel pour réduire la taille
CREATE INDEX idx_active_orders
ON orders (customer_id, order_date)
WHERE status = 'active';
-- PostgreSQL : vue matérialisée + refresh
CREATE MATERIALIZED VIEW mv_monthly_revenue AS
SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS revenue
FROM orders GROUP BY 1;
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_monthly_revenue;
-- SQL Server : indexed view (requiert WITH SCHEMABINDING)
CREATE VIEW dbo.vw_monthly_revenue WITH SCHEMABINDING AS
SELECT DATEFROMPARTS(YEAR(order_date), MONTH(order_date), 1) AS month,
SUM(amount) AS revenue, COUNT_BIG(*) AS cnt
FROM dbo.orders GROUP BY DATEFROMPARTS(YEAR(order_date), MONTH(order_date), 1);
CREATE UNIQUE CLUSTERED INDEX ix_mv ON dbo.vw_monthly_revenue (month);
| Anti-pattern | Risque | Correction |
|---|---|---|
LAST_VALUE sans frame explicite | Retourne la ligne courante, pas la dernière | Ajouter ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING |
| CTE récursive sans limite de profondeur | Boucle infinie sur données cycliques | Ajouter WHERE depth < N ou MAXRECURSION N (SQL Server) |
Window function dans WHERE | Erreur syntaxique | Encapsuler dans une CTE ou sous-requête, filtrer ensuite |
SELECT DISTINCT + window function | Résultats incohérents si le DISTINCT s'applique avant | Utiliser une CTE intermédiaire |
| Pivot dynamique côté SQL | Colonnes inconnues à compile-time | Générer le SQL en application ou via STRING_AGG + EXEC |
Trop de window functions sur le même OVER non nommé | Recalcul répété | Factoriser avec WINDOW w AS (...) (PostgreSQL) ou CTE |
| Requête analytique sur table non partitionnée (milliards de lignes) | Full scan coûteux | Ajouter un filtre de date, ou partitionner la table |
WINDOW w AS (...) quand la même clause est réutilisée (lisibilité + plan partagé sur PostgreSQL 16+).WHERE order_date >= CURRENT_DATE - INTERVAL '7 days').ROWS plutôt que RANGE dans le frame — RANGE est plus lent car il gère les ex-aequo dynamiquement.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/claude-skills-collection:data-sql-advanced-analyticsfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collection348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests".Other plugins' skills for the same job