sqlcmd.net validated sql reference

#group-by

Commands grouped around the same concept, pattern, or recurring problem.

9 commands with this tag Browse related patterns quickly
advanced aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Aggregate Rows Conditionally With CASE Inside An Aggregate

Use `CASE WHEN` inside `SUM` or `COUNT` to produce multiple metrics from a single pass over grouped data.

advanced json MySQL MariaDB SQL Server PostgreSQL SQLite

Aggregate Rows Into A JSON Array

Collect values from multiple rows into a single JSON array, ordered and grouped by other columns.

advanced aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Concatenate Values Within A Group

Aggregate multiple string values from grouped rows into a single delimited string.

intermediate grouping MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Grouped Results With HAVING

Use `HAVING` to filter aggregate results after `GROUP BY`, the same way `WHERE` filters individual rows before grouping.

intermediate data-quality MySQL MariaDB SQL Server PostgreSQL SQLite

Find Duplicate Values With GROUP BY And HAVING

Group rows by the candidate key and keep only values that appear more than once.

intermediate grouping MySQL MariaDB SQL Server PostgreSQL SQLite

Group Rows And Count

Aggregate rows by category with `GROUP BY` and count how many rows fall into each group.

intermediate date-time MySQL MariaDB SQL Server PostgreSQL SQLite

Group Rows By Month

Bucket dates into month starts, then aggregate counts or totals per month.

intermediate aggregation MySQL MariaDB SQL Server PostgreSQL

Group Rows By Multiple Columns

Use more than one column in `GROUP BY` when each combination defines a separate aggregate bucket.

intermediate grouping MySQL MariaDB SQL Server PostgreSQL SQLite

Use WHERE Before GROUP BY And HAVING After

`WHERE` filters individual rows before grouping. `HAVING` filters grouped results after aggregates are computed.