|< < 38 > >|

Aggregation with grouping

Combining with other operations

  • Grouping and aggregation happens at the end, after joins and restrictions in the from and where clauses.

Example

For each customer, find total unpaid for purchases at least one year ago.
select customer_id, sum(unpaid) from purchase where age(purchase_date) > interval '1 year' group by customer_id

|< < 38 > >|