Browse by topic

SQL & Local Analytics

Practical SQL for analysts — the patterns you actually reuse, from joins and window functions to running analytics locally with DuckDB.

How to Pivot Data in SQL: PIVOT vs CASE WHEN

Turn rows into columns in SQL with CASE WHEN or PIVOT. Copy-paste examples for PostgreSQL, SQL Server, Snowflake and DuckDB, plus how to unpivot.

sqlpivotdata analysisduckdb

Prompting an LLM for SQL You Can Trust

How to get reliable SQL from ChatGPT, Claude or Copilot. What context to give, how to use examples, and the checks that catch wrong joins and made-up columns.

llmsqlprompt engineeringai for analysts

SQL CTE vs Subquery vs Temp Table: Which to Use

CTE, subquery or temp table? A plain-English comparison for analysts, with examples, the performance trade-offs, and a simple rule for choosing.

sqldata analyticsctequery performance

How to Find and Fix Duplicate Rows in SQL

Find duplicate rows in SQL with GROUP BY and ROW_NUMBER, then remove them safely. Copy-paste queries, the traps to avoid, and how to stop duplicates coming back.

sqldata qualitydata cleaningdata analytics

Cohort Retention Analysis in SQL, Step by Step

Build a cohort retention table in SQL in three steps. Includes a full PostgreSQL query, how to read the triangle, and the mistakes that skew retention.

sqlcohort analysisretentiondata analytics

SQL window functions: 10 patterns for real analysis

Window functions keep your rows while you calculate across them. Learn ten patterns: ranking, deduplication, running totals, LAG, cohorts and streaks.

sqlwindow functionsdata analysispayments analytics