SQL · Aggregation and grouping

group by expression

Groups by a computed value. PostgreSQL needs the same expression in SELECT.

Syntax
group by date_trunc('month', created_at)

Example

Open in the lab

Notes

SQLite equivalents use strftime().

More in this group

count() filter clause group by having min() / max() rollup string_agg / group_concat sum() / avg()

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course