Vol. I · A Postgres HandbookTwelve chapters · · 756 queries

The Query & the Schema

A reading-room reference for writing PostgreSQL by hand — selects to window functions, with the schema in plain view.

FrontChaptersSchemaColophon
Chapters · WHERE & Filtering · Query 026 / 030
IntermediateWHERE & Filtering

Find customers who joined in Q1 of any year

The query

SQL
SELECT name, joined_at, country
FROM customers
WHERE EXTRACT(MONTH FROM joined_at) IN (1, 2, 3)
ORDER BY joined_at DESC;
Tested against PostgreSQL 16

Note

“EXTRACT(MONTH) returns 1-12. Q1 = months 1,2,3. Use for seasonal analysis.

Tables referenced

  • customers6 cols

← Previous

Find products with price ending in .99

Next →

Find projects that are overdue

The Query & the Schema

Set in Fraunces and Inter Tight. Printed on parchment, in oxblood and ink. No tracking, no accounts, no JavaScript on the answer pages beyond what your browser needs to copy a query.

Compiled for Postgres 16 · MMXXVI