Skip to content
Back to skills

608 Common Patterns 00359c55

ASecurity

SQL templates for frequent analysis types. > **Note:** Examples use Snowflake syntax. For other databases: > - `DATEADD(day, -7, x)` → PostgreSQL: `x - INTERVAL '7 days'` → BigQuery: `DATE_SUB(x, INTERVAL 7 DAY)` > - `DATE_TRUNC('week', x)` → BigQuery: `DATE_TRUNC(x, WEEK)`

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
databasessqlgitdatabase

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 608-common-patterns_00359c55 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 608 Common Patterns 00359c55?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 608 Common Patterns 00359c55
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-608-common-patterns-00359c55/badge)](https://www.skillsdirectory.com/skills/tools-only-608-common-patterns-00359c55)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Common Analysis Patterns](#common-analysis-patterns)
  - [Trend Over Time](#trend-over-time)
  - [Comparison (Period over Period)](#comparison-period-over-period)
  - [Top N Analysis](#top-n-analysis)
  - [Distribution / Histogram](#distribution--histogram)
  - [Cohort Analysis](#cohort-analysis)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Common Analysis Patterns

SQL templates for frequent analysis types.

> **Note:** Examples use Snowflake syntax. For other databases:
> - `DATEADD(day, -7, x)` → PostgreSQL: `x - INTERVAL '7 days'` → BigQuery: `DATE_SUB(x, INTERVAL 7 DAY)`
> - `DATE_TRUNC('week', x)` → BigQuery: `DATE_TRUNC(x, WEEK)`

## Trend Over Time
```sql
SELECT
    DATE_TRUNC('week', event_date) as week,
    COUNT(*) as events,
    COUNT(DISTINCT user_id) as unique_users
FROM events
WHERE event_date >= DATEADD(month, -3, CURRENT_DATE)
GROUP BY 1
ORDER BY 1
```

## Comparison (Period over Period)
```sql
SELECT
    CASE
        WHEN date_col >= DATEADD(day, -7, CURRENT_DATE) THEN 'This Week'
        ELSE 'Last Week'
    END as period,
    SUM(amount) as total,
    COUNT(DISTINCT customer_id) as customers
FROM orders
WHERE date_col >= DATEADD(day, -14, CURRENT_DATE)
GROUP BY 1
```

## Top N Analysis
```sql
SELECT
    customer_name,
    SUM(revenue) as total_revenue,
    COUNT(*) as order_count
FROM orders
JOIN customers USING (customer_id)
WHERE order_date >= '2024-01-01'
GROUP BY customer_name
ORDER BY total_revenue DESC
LIMIT 10
```

## Distribution / Histogram
```sql
SELECT
    FLOOR(amount / 100) * 100 as bucket,
    COUNT(*) as frequency
FROM orders
GROUP BY 1
ORDER BY 1
```

## Cohort Analysis
```sql
WITH first_purchase AS (
    SELECT
        customer_id,
        DATE_TRUNC('month', MIN(order_date)) as cohort_month
    FROM orders
    GROUP BY customer_id
)
SELECT
    fp.cohort_month,
    DATE_TRUNC('month', o.order_date) as activity_month,
    COUNT(DISTINCT o.customer_id) as active_customers
FROM orders o
JOIN first_purchase fp USING (customer_id)
GROUP BY 1, 2
ORDER BY 1, 2
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.