How do we group timestamps into standard calendar boundaries like months or weeks?
DATE_TRUNC truncates timestamps to specified boundaries (year, month, week, day) for aggregations.
Monthly active metrics, weekly revenue summaries, cohort analysis, dashboard rollups.
SELECT
DATE_TRUNC('month', order_date)
AS order_month,
COUNT(*) AS orders
FROM orders
GROUP BY
DATE_TRUNC('month', order_date);Practice typing production-grade SQL code for DATE_TRUNC.