SQL Formula Library
Browse ready-to-use formula templates for Excel, Google Sheets, SQL, and regex. Each formula includes a step-by-step breakdown, edge-case warnings, and real-world examples.
AI-generated SQL queries for PostgreSQL, MySQL, and SQL Server. JOINs, window functions, CTEs, and aggregations.
JOIN Three Tables
Most real queries need data from 3+ tables. Here's the clean pattern for multi-table JOINs that actually performs well.
SQL Window Functions
Window functions let you calculate across rows without grouping. Rankings, running totals, and row comparisons — all in one query.
GROUP BY With HAVING
WHERE filters rows before grouping. HAVING filters groups after aggregation. Know when to use each.
CTE (Common Table Expression)
CTEs (WITH clause) break complex queries into named steps. Replace nested subqueries with clean, readable, maintainable SQL.
CASE WHEN Statement
CASE WHEN is SQL's IF-THEN-ELSE. Categorize data, create conditional aggregations, and build pivot-like outputs.
COALESCE Function
COALESCE returns the first non-NULL value from a list. Essential for default values, NULL-safe calculations, and clean query output.
SQL Subqueries
Subqueries let you use the result of one query inside another. Essential for filtering, comparisons, and derived tables.
Can't find what you need?
Describe any formula in plain English and Formula Genius will generate it, explain it, and validate it — instantly.