On this page
  1. GROUP BY
  2. Syntax & Overview
  3. Notes & Best Practices
  4. Example

GROUP BY

Prev: `WHERE` | Up: clauses | Next: `HAVING`
Rel: clauses, SQL Query Execution Lifecycle
Ref: PostgreSQL — SQL Commands
Tags: #public #databases #sql #clauses #tier/core


Syntax & Overview

GROUP BY user_id

Partitions filtered rows into groups for aggregate computation.

Notes & Best Practices

Example

SELECT status, COUNT(*) AS order_count, SUM(total) AS revenue
FROM orders
GROUP BY status;

Linked from

Related notes