sql-queries
Skill26k starsChanged 10 months agoApache-2.0View on GitHub
Write correct, performant SQL across all major data warehouse dialects (Snowflake, BigQuery, Databricks, PostgreSQL, etc.). Use when writing queries, optimizing slow SQL, translating between dialects, or building complex analytical queries with CTEs, window functions, or aggregations.
8 other projects use a version of this, 1 of them edited; 1 of 1 edited versions we compared changed its rules.
How people change it
1 of 1 edited versions changed its rules.
Of the 1 edited version we compared: 1 made changes of their own.
Rules people drop
- Use
EXPLAIN ANALYZEto profile queriesdropped by 1 of 1 - Create indexes on frequently filtered/joined columnsdropped by 1 of 1
- Use
EXISTSoverINfor correlated subqueriesdropped by 1 of 1 - Use connection pooling for concurrent accessdropped by 1 of 1
- Use clustering keys on large tables (not traditional indexes)dropped by 1 of 1
- Use
RESULT_SCAN(LAST_QUERY_ID())to avoid re-running expensive queriesdropped by 1 of 1 - Use transient tables for staging/temp datadropped by 1 of 1
- Always filter on partition columns (usually date) to reduce bytes scanneddropped by 1 of 1
We split this file and each edited version into the rules they give an agent and match them by wording. A version that adds no rule of its own and has not changed since this file last did reads as an older text, so what it lacks is not counted as dropped. We keep no past texts of a file, so that is inferred, and an edited version that started from an older text still counts its gaps as drops.
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Most recently taken up by
- arjunprabhulal/agent-skillstheir own version, first seen Aug 3, 2026
- yuusakuri/agent-skillstheir own version, first seen Jul 30, 2026
- xeroc/skillstheir own version, first seen Jul 17, 2026
- maeng777/claude-skillstheir own version, first seen Jun 19, 2026
- miovrag/claude-skillstheir own version, first seen Jun 12, 2026
- miptah21/skillsedited, first seen May 26, 2026
Who's talking about anthropics/knowledge-work-plugins
- @tommis.fi“github.com/anthropics/k...”Bluesky · May 24, 2026 · 5 likes
- A Hacker News story“Anthropic – Legal Productivity Plugin”Hacker News · Feb 4, 2026 · 4 points
- A Hacker News story“Claude open source knowledge Work Plugins”Hacker News · Jan 30, 2026 · 4 points
- Kilo-Org/kilo-marketplace“Add build-dashboard skill”GitHub · Jun 23, 2026 · 2 reactions
- @github-trending.bsky.social“🚀 Skyrocketing! 🚀 (200+ new stars) 📦 anthropics / knowledge-work-plugins ⭐ 13,162 (+486) 🗒 Python Open …”Bluesky · May 24, 2026 · 2 likes
The biggest 5 of 57 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 57
Talked about on GitHub, Bluesky and Hacker News (57 times).
On GitHub · 50
- Jun 23, 2026Add build-dashboard skill — Kilo-Org/kilo-marketplace2 reactions · 1 comment
- Nov 24, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 2baf6d1 → 5e504ae — sudosubin/agents.nix0 reactions
- Nov 24, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-19 → 0-unstable-2026-11-23 — sudosubin/agents.nix0 reactions
- Nov 24, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-19 → 0-unstable-2026-11-23 — sudosubin/agents.nix0 reactions
- Nov 23, 2026chore(skills): bump the skill-packs group across 1 directory with 19 updates — solanabr/ai-kit0 reactions · 2 comments
45 more on GitHub
- Nov 23, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-19 → 0-unstable-2026-11-23 — sudosubin/agents.nix0 reactions
- Nov 20, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-18 → 0-unstable-2026-11-19 — sudosubin/agents.nix0 reactions
- Nov 19, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-18 → 0-unstable-2026-11-19 — sudosubin/agents.nix0 reactions
- Nov 19, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-18 → 0-unstable-2026-11-19 — sudosubin/agents.nix0 reactions
- Nov 18, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-13 → 0-unstable-2026-11-18 — sudosubin/agents.nix0 reactions
- Nov 18, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-13 → 0-unstable-2026-11-18 — sudosubin/agents.nix0 reactions
- Nov 18, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-13 → 0-unstable-2026-11-18 — sudosubin/agents.nix0 reactions
- Nov 16, 2026deps: actualiza skills (auditar) — savaf/dotfiles0 reactions
- Nov 16, 2026Feature: 3 role additions adapted from Anthropic knowledge-work-plugins (Sales deal skills, Legal helper, Accounting close) — amgadbarkat-ab/Ark-Agent0 reactions
- Nov 15, 2026[P1 WORK PACKS] Composable knowledge-work skills, commands, connectors and real professional workflows — loftwah/app-composer0 reactions
- Nov 14, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 43ccfc0 → e91a134 — sudosubin/agents.nix0 reactions
- Nov 14, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 43ccfc0 → e91a134 — sudosubin/agents.nix0 reactions
- Nov 13, 2026agent-skills.github.anthropics.knowledge-work-plugins: 43ccfc0 → e91a134 — sudosubin/agents.nix0 reactions
- Nov 13, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 02717ef → 43ccfc0 — sudosubin/agents.nix0 reactions
- Nov 13, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 02717ef → 43ccfc0 — sudosubin/agents.nix0 reactions
- Nov 13, 2026agent-skills.github.anthropics.knowledge-work-plugins: 02717ef → 43ccfc0 — sudosubin/agents.nix0 reactions
- Nov 13, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-12 → 0-unstable-2026-11-13 — sudosubin/agents.nix0 reactions
- Nov 13, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-12 → 0-unstable-2026-11-13 — sudosubin/agents.nix0 reactions
- Nov 13, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-12 → 0-unstable-2026-11-13 — sudosubin/agents.nix0 reactions
- Nov 12, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-11 → 0-unstable-2026-11-12 — sudosubin/agents.nix0 reactions
- Nov 12, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-11 → 0-unstable-2026-11-12 — sudosubin/agents.nix0 reactions
- Nov 12, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-11 → 0-unstable-2026-11-12 — sudosubin/agents.nix0 reactions
- Nov 12, 2026investigation: evaluate anthropics/knowledge-work-plugins — gordonpn/dotfiles0 reactions
- Nov 11, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-09 → 0-unstable-2026-11-11 — sudosubin/agents.nix0 reactions
- Nov 11, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-09 → 0-unstable-2026-11-11 — sudosubin/agents.nix0 reactions
- Nov 11, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-09 → 0-unstable-2026-11-11 — sudosubin/agents.nix0 reactions
- Nov 10, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-07 → 0-unstable-2026-11-09 — sudosubin/agents.nix0 reactions
- Nov 10, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-07 → 0-unstable-2026-11-09 — sudosubin/agents.nix0 reactions
- Nov 9, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-07 → 0-unstable-2026-11-09 — sudosubin/agents.nix0 reactions
- Nov 9, 2026deps: actualiza skills (auditar) — savaf/dotfiles0 reactions
- Nov 7, 2026engineering plugin — mattbutlerengineering/skills0 reactions
- Nov 7, 2026knowledge base improvements — mattbutlerengineering/skills0 reactions
- Nov 7, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-06 → 0-unstable-2026-11-07 — sudosubin/agents.nix0 reactions
- Nov 7, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-06 → 0-unstable-2026-11-07 — sudosubin/agents.nix0 reactions
- Nov 7, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-06 → 0-unstable-2026-11-07 — sudosubin/agents.nix0 reactions
- Nov 6, 2026deps: actualiza skills (auditar) — savaf/dotfiles0 reactions
- Nov 6, 2026research: instilling placement and architecture judgment in coding agents (skills, agents, rules, checks) — dfadler/agent-config0 reactions
- Nov 6, 2026agent-skills.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-04 → 0-unstable-2026-11-06 — sudosubin/agents.nix0 reactions
- Nov 6, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-04 → 0-unstable-2026-11-06 — sudosubin/agents.nix0 reactions
- Nov 6, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-11-04 → 0-unstable-2026-11-06 — sudosubin/agents.nix0 reactions
- Nov 4, 2026claude-code-marketplaces.github.anthropics.knowledge-work-plugins: 0-unstable-2026-10-28 → 0-unstable-2026-11-04 — sudosubin/agents.nix0 reactions
- Nov 4, 2026claude-code-plugins.github.anthropics.knowledge-work-plugins: 0-unstable-2026-10-28 → 0-unstable-2026-11-04 — sudosubin/agents.nix0 reactions
- Oct 27, 2026scan: 2026-10-27 daily discovery — mattbutlerengineering/ai-tooling0 reactions
- Oct 24, 2026📈 Bản tin xu hướng AI mã nguồn mở 2026-10-24 — thanhtantran/agents-radar0 reactions
- Oct 24, 2026🔥 GitHub Trending AI 早报 · 2026-10-24 · Top 6 项目 — happydog-intj/ai-xiaohongshu-daily0 reactions
On Bluesky · 5
- May 24, 2026github.com/anthropics/k... — @tommis.fi5 likes and reposts
- May 24, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 anthropics / knowledge-work-plugins ⭐ 13,162 (+486) 🗒 Python Open source repository of plugins… — @github-trending.bsky.social2 likes and reposts · 1 reply
- May 25, 2026📈 Today's GitHub Trending: 1. https://github.com/Lum1104/Understand-Anything - TypeScript, 5625 stars today 2.… — @ghtrend.newsmast.social.ap.brid.gy1 likes and repost · 1 reply
- May 24, 2026今日のGitHubトレンド anthropics/knowledge-work-plugins Claudeを特定の役割や企業に最適化したスペシャリストにするためのプラグイン集です。 Claude CoworkやClaude… — @dailygithubtrends.bsky.social1 likes and repost
- Oct 20, 2026🚀 Skyrocketing! 🚀 (200+ new stars) 📦 anthropics / knowledge-work-plugins ⭐ 30,616 (+262) 🗒 Python Open source repository of plugins… — @github-trending.bsky.social0 likes and reposts · 1 reply
On Hacker News · 2
- Feb 4, 2026Anthropic – Legal Productivity Plugin4 points · 2 comments
- Jan 30, 2026Claude open source knowledge Work Plugins4 points
Used with
Projects with it also use brainstorm-experiments-new, ideal-customer-profile and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
skytiger6724Skillbrainstorm-experiments-new
Design lean startup experiments (pretotypes) for a new product. Creates XYZ hypotheses and suggests low-effort validation methods like landing pages, explainer videos, and pre-orders. Use when validating a new product idea, creating pretotypes, or testing market demand.
Also in 5 projects that use this
skytiger6724Skillideal-customer-profile
Identify the Ideal Customer Profile (ICP) from research data with demographics, behaviors, JTBD, and needs. Use when defining your ICP, analyzing PMF survey data, or understanding who your best customers are.
Also in 5 projects that use this
launchapp-devSkillinterview-script
Create a structured user interview script with warm-up, core exploration, and wrap-up sections. Use when preparing for user research interviews to ensure consistent, insightful conversations.
Also in 5 projects that use this
45ckSkillpestle-analysis
Also in 4 projects that use this
- +8 more from skytiger6724
Other versions8 projects use a version of this.
Word for word · 1
- jmolz/m0lz.01★ 0100% same
Edited · 1
- miptah21/skills★ 266% same
Wrote their own version · 6
- arjunprabhulal/agent-skills★ 4same name
- skytiger6724/qwen-skills★ 2same name
- yuusakuri/agent-skills★ 2same name
- miovrag/claude-skills★ 1same name
- xeroc/skills★ 1same name
- maeng777/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository253 other files it gives its agents.
- partner-built/zoom-plugin/AGENTS.mdAGENTS.md
- partner-built/slack/CLAUDE.mdCLAUDE.md
- instrument-data-to-allotropeSkill
- nextflow-developmentSkill
- scientific-problem-selectionSkill
- scvi-toolsSkill
- single-cell-rna-qcSkill
- startSkill
- cowork-plugin-customizerSkill
- create-cowork-pluginSkill
- customer-escalationSkill
- customer-researchSkill
- draft-responseSkill
- kb-articleSkill
- ticket-triageSkill
- analyzeSkill
- build-dashboardSkill
- create-vizSkill
- data-context-extractorSkill
- data-visualizationSkill
- explore-dataSkill
- statistical-analysisSkill
- validate-dataSkill
- write-querySkill
- accessibility-reviewSkill
- design-critiqueSkill
- design-handoffSkill
- design-systemSkill
- research-synthesisSkill
- user-researchSkill
- ux-copySkill
- architectureSkill
- code-reviewSkill
- debugSkill
- deploy-checklistSkill
- documentationSkill
- incident-responseSkill
- standupSkill
- system-designSkill
- tech-debtSkill
- testing-strategySkill
- digestSkill
- knowledge-synthesisSkill
- searchSkill
- search-strategySkill
- source-managementSkill
- audit-supportSkill
- close-managementSkill
- financial-statementsSkill
- journal-entry-prepSkill
- journal-entrySkill
- reconciliationSkill
- sox-testingSkill
- variance-analysisSkill
- comp-analysisSkill
- draft-offerSkill
- interview-prepSkill
- onboardingSkill
- org-planningSkill
- people-reportSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
25 rules. 0 are common, 13 are distinctive, and 12 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
13
Distinctive
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 9
Write correct, performant, readable SQL across all major data warehouse dialects.
- Very specific: line 65
Use EXPLAIN ANALYZE to profile queries
- Distinctive: line 66
Create indexes on frequently filtered/joined columns
- Very specific: line 67
Use EXISTS over IN for correlated subqueries
- Distinctive: line 69
Use connection pooling for concurrent access
- Distinctive: line 126
Use clustering keys on large tables (not traditional indexes)
- Very specific: line 129
Use RESULT_SCAN(LAST_QUERY_ID()) to avoid re-running expensive queries
- Distinctive: line 130
Use transient tables for staging/temp data
- Distinctive: line 185
Always filter on partition columns (usually date) to reduce bytes scanned
- Distinctive: line 186
Use clustering for frequently filtered columns within partitions
- Very specific: line 187
Use APPROX_COUNT_DISTINCT() for large-scale cardinality estimates
- Very specific: line 188
Avoid SELECT * -- billing is per-byte scanned
- Very specific: line 189
Use DECLARE and SET for parameterized scripts
- Distinctive: line 226
Use sort keys for frequently filtered columns (SORTKEY)
- Very specific: line 227
Use EXPLAIN to check query plan
- Very specific: line 228
Avoid cross-node data movement (watch for DS_BCAST and DS_DIST)
- Distinctive: line 230
Use late-binding views for schema flexibility
- Very specific: line 272
Use Delta Lake's OPTIMIZE and ZORDER for query performance
- Very specific: line 274
Use CACHE TABLE for frequently accessed datasets
- Distinctive: line 421
When a query fails:
- Very specific: line 423
Syntax errors: Check for dialect-specific syntax (e.g., ILIKE not available in BigQuery, SAFE_DIVIDE only in BigQuery)
- Distinctive: line 424
Column not found: Verify column names against schema -- check for typos, case sensitivity (PostgreSQL is case-sensitive for quoted …
- Very specific: line 426
Division by zero: Use NULLIF(denominator, 0) or dialect-specific safe division
- Distinctive: line 427
Ambiguous columns: Always qualify column names with table alias in JOINs
- Distinctive: line 428
Group by errors: All non-aggregated columns must be in GROUP BY (except in BigQuery which allows grouping by alias)
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SQL Queries Skill
Write correct, performant, readable SQL across all major data warehouse dialects.
Dialect-Specific Reference
PostgreSQL (including Aurora, RDS, Supabase, Neon)
Date/time:
-- Current date/time
CURRENT_DATE, CURRENT_TIMESTAMP, NOW()
-- Date arithmetic
date_column + INTERVAL '7 days'
date_column - INTERVAL '1 month'
-- Truncate to period
DATE_TRUNC('month', created_at)
-- Extract parts
EXTRACT(YEAR FROM created_at)
EXTRACT(DOW FROM created_at) -- 0=Sunday
-- Format
TO_CHAR(created_at, 'YYYY-MM-DD')String functions:
-- Concatenation
first_name || ' ' || last_name
CONCAT(first_name, ' ', last_name)
-- Pattern matching
column ILIKE '%pattern%' -- case-insensitive
column ~ '^regex_pattern$' -- regex
-- String manipulation
LEFT(str, n), RIGHT(str, n)
SPLIT_PART(str, delimiter, position)
REGEXP_REPLACE(str, pattern, replacement)Arrays and JSON:
-- JSON access
data->>'key' -- text
data->'nested'->'key' -- json
data#>>'{path,to,key}' -- nested text
-- Array operations
ARRAY_AGG(column)
ANY(array_column)
array_column @> ARRAY['value']Performance tips:
- Use
EXPLAIN ANALYZEto profile queries - Create indexes on frequently filtered/joined columns
- Use
EXISTSoverINfor correlated subqueries - Partial indexes for common filter conditions
- Use connection pooling for concurrent access
Snowflake
Date/time:
-- Current date/time
CURRENT_DATE(), CURRENT_TIMESTAMP(), SYSDATE()
-- Date arithmetic
DATEADD(day, 7, date_column)
DATEDIFF(day, start_date, end_date)
-- Truncate to period
DATE_TRUNC('month', created_at)
-- Extract parts
YEAR(created_at), MONTH(created_at), DAY(created_at)
DAYOFWEEK(created_at)
-- Format
TO_CHAR(created_at, 'YYYY-MM-DD')String functions:
-- Case-insensitive by default (depends on collation)
column ILIKE '%pattern%'
REGEXP_LIKE(column, 'pattern')
-- Parse JSON
column:key::string -- dot notation for VARIANT
PARSE_JSON('{"key": "value"}')
GET_PATH(variant_col, 'path.to.key')
-- Flatten arrays/objects
SELECT f.value FROM table, LATERAL FLATTEN(input => array_col) fSemi-structured data:
-- VARIANT type access
data:customer:name::STRING
data:items[0]:price::NUMBER
-- Flatten nested structures
SELECT
t.id,
item.value:name::STRING as item_name,
item.value:qty::NUMBER as quantity
FROM my_table t,
LATERAL FLATTEN(input => t.data:items) itemPerformance tips:
- Use clustering keys on large tables (not traditional indexes)
- Filter on clustering key columns for partition pruning
- Set appropriate warehouse size for query complexity
- Use
RESULT_SCAN(LAST_QUERY_ID())to avoid re-running expensive queries - Use transient tables for staging/temp data
BigQuery (Google Cloud)
Date/time:
-- Current date/time
CURRENT_DATE(), CURRENT_TIMESTAMP()
-- Date arithmetic
DATE_ADD(date_column, INTERVAL 7 DAY)
DATE_SUB(date_column, INTERVAL 1 MONTH)
DATE_DIFF(end_date, start_date, DAY)
TIMESTAMP_DIFF(end_ts, start_ts, HOUR)
-- Truncate to period
DATE_TRUNC(created_at, MONTH)
TIMESTAMP_TRUNC(created_at, HOUR)
-- Extract parts
EXTRACT(YEAR FROM created_at)
EXTRACT(DAYOFWEEK FROM created_at) -- 1=Sunday
-- Format
FORMAT_DATE('%Y-%m-%d', date_column)
FORMAT_TIMESTAMP('%Y-%m-%d %H:%M:%S', ts_column)String functions:
-- No ILIKE, use LOWER()
LOWER(column) LIKE '%pattern%'
REGEXP_CONTAINS(column, r'pattern')
REGEXP_EXTRACT(column, r'pattern')
-- String manipulation
SPLIT(str, delimiter) -- returns ARRAY
ARRAY_TO_STRING(array, delimiter)Arrays and structs:
-- Array operations
ARRAY_AGG(column)
UNNEST(array_column)
ARRAY_LENGTH(array_column)
value IN UNNEST(array_column)
-- Struct access
struct_column.field_namePerformance tips:
- Always filter on partition columns (usually date) to reduce bytes scanned
- Use clustering for frequently filtered columns within partitions
- Use
APPROX_COUNT_DISTINCT()for large-scale cardinality estimates - Avoid
SELECT *-- billing is per-byte scanned - Use
DECLAREandSETfor parameterized scripts - Preview query cost with dry run before executing large queries
Redshift (Amazon)
Date/time:
-- Current date/time
CURRENT_DATE, GETDATE(), SYSDATE
-- Date arithmetic
DATEADD(day, 7, date_column)
DATEDIFF(day, start_date, end_date)
-- Truncate to period
DATE_TRUNC('month', created_at)
-- Extract parts
EXTRACT(YEAR FROM created_at)
DATE_PART('dow', created_at)String functions:
-- Case-insensitive
column ILIKE '%pattern%'
REGEXP_INSTR(column, 'pattern') > 0
-- String manipulation
SPLIT_PART(str, delimiter, position)
LISTAGG(column, ', ') WITHIN GROUP (ORDER BY column)Performance tips:
- Design distribution keys for collocated joins (DISTKEY)
- Use sort keys for frequently filtered columns (SORTKEY)
- Use
EXPLAINto check query plan - Avoid cross-node data movement (watch for DS_BCAST and DS_DIST)
ANALYZEandVACUUMregularly- Use late-binding views for schema flexibility
Databricks SQL
Date/time:
-- Current date/time
CURRENT_DATE(), CURRENT_TIMESTAMP()
-- Date arithmetic
DATE_ADD(date_column, 7)
DATEDIFF(end_date, start_date)
ADD_MONTHS(date_column, 1)
-- Truncate to period
DATE_TRUNC('MONTH', created_at)
TRUNC(date_column, 'MM')
-- Extract parts
YEAR(created_at), MONTH(created_at)
DAYOFWEEK(created_at)Delta Lake features:
-- Time travel
SELECT * FROM my_table TIMESTAMP AS OF '2024-01-15'
SELECT * FROM my_table VERSION AS OF 42
-- Describe history
DESCRIBE HISTORY my_table
-- Merge (upsert)
MERGE INTO target USING source
ON target.id = source.id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *Performance tips:
- Use Delta Lake's
OPTIMIZEandZORDERfor query performance - Leverage Photon engine for compute-intensive queries
- Use
CACHE TABLEfor frequently accessed datasets - Partition by low-cardinality date columns
Common SQL Patterns
Window Functions
-- Ranking
ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC)
RANK() OVER (PARTITION BY category ORDER BY revenue DESC)
DENSE_RANK() OVER (ORDER BY score DESC)
-- Running totals / moving averages
SUM(revenue) OVER (ORDER BY date_col ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as running_total
AVG(revenue) OVER (ORDER BY date_col ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) as moving_avg_7d
-- Lag / Lead
LAG(value, 1) OVER (PARTITION BY entity ORDER BY date_col) as prev_value
LEAD(value, 1) OVER (PARTITION BY entity ORDER BY date_col) as next_value
-- First / Last value
FIRST_VALUE(status) OVER (PARTITION BY user_id ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
LAST_VALUE(status) OVER (PARTITION BY user_id ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
-- Percent of total
revenue / SUM(revenue) OVER () as pct_of_total
revenue / SUM(revenue) OVER (PARTITION BY category) as pct_of_categoryCTEs for Readability
WITH
-- Step 1: Define the base population
base_users AS (
SELECT user_id, created_at, plan_type
FROM users
WHERE created_at >= DATE '2024-01-01'
AND status = 'active'
),
-- Step 2: Calculate user-level metrics
user_metrics AS (
SELECT
u.user_id,
u.plan_type,
COUNT(DISTINCT e.session_id) as session_count,
SUM(e.revenue) as total_revenue
FROM base_users u
LEFT JOIN events e ON u.user_id = e.user_id
GROUP BY u.user_id, u.plan_type
),
-- Step 3: Aggregate to summary level
summary AS (
SELECT
plan_type,
COUNT(*) as user_count,
AVG(session_count) as avg_sessions,
SUM(total_revenue) as total_revenue
FROM user_metrics
GROUP BY plan_type
)
SELECT * FROM summary ORDER BY total_revenue DESC;Cohort Retention
WITH cohorts AS (
SELECT
user_id,
DATE_TRUNC('month', first_activity_date) as cohort_month
FROM users
),
activity AS (
SELECT
user_id,
DATE_TRUNC('month', activity_date) as activity_month
FROM user_activity
)
SELECT
c.cohort_month,
COUNT(DISTINCT c.user_id) as cohort_size,
COUNT(DISTINCT CASE
WHEN a.activity_month = c.cohort_month THEN a.user_id
END) as month_0,
COUNT(DISTINCT CASE
WHEN a.activity_month = c.cohort_month + INTERVAL '1 month' THEN a.user_id
END) as month_1,
COUNT(DISTINCT CASE
WHEN a.activity_month = c.cohort_month + INTERVAL '3 months' THEN a.user_id
END) as month_3
FROM cohorts c
LEFT JOIN activity a ON c.user_id = a.user_id
GROUP BY c.cohort_month
ORDER BY c.cohort_month;Funnel Analysis
WITH funnel AS (
SELECT
user_id,
MAX(CASE WHEN event = 'page_view' THEN 1 ELSE 0 END) as step_1_view,
MAX(CASE WHEN event = 'signup_start' THEN 1 ELSE 0 END) as step_2_start,
MAX(CASE WHEN event = 'signup_complete' THEN 1 ELSE 0 END) as step_3_complete,
MAX(CASE WHEN event = 'first_purchase' THEN 1 ELSE 0 END) as step_4_purchase
FROM events
WHERE event_date >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY user_id
)
SELECT
COUNT(*) as total_users,
SUM(step_1_view) as viewed,
SUM(step_2_start) as started_signup,
SUM(step_3_complete) as completed_signup,
SUM(step_4_purchase) as purchased,
ROUND(100.0 * SUM(step_2_start) / NULLIF(SUM(step_1_view), 0), 1) as view_to_start_pct,
ROUND(100.0 * SUM(step_3_complete) / NULLIF(SUM(step_2_start), 0), 1) as start_to_complete_pct,
ROUND(100.0 * SUM(step_4_purchase) / NULLIF(SUM(step_3_complete), 0), 1) as complete_to_purchase_pct
FROM funnel;Deduplication
-- Keep the most recent record per key
WITH ranked AS (
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY entity_id
ORDER BY updated_at DESC
) as rn
FROM source_table
)
SELECT * FROM ranked WHERE rn = 1;Error Handling and Debugging
When a query fails:
- Syntax errors: Check for dialect-specific syntax (e.g.,
ILIKEnot available in BigQuery,SAFE_DIVIDEonly in BigQuery) - Column not found: Verify column names against schema -- check for typos, case sensitivity (PostgreSQL is case-sensitive for quoted identifiers)
- Type mismatches: Cast explicitly when comparing different types (
CAST(col AS DATE),col::DATE) - Division by zero: Use
NULLIF(denominator, 0)or dialect-specific safe division - Ambiguous columns: Always qualify column names with table alias in JOINs
- Group by errors: All non-aggregated columns must be in GROUP BY (except in BigQuery which allows grouping by alias)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

