sqlcmd.net validated sql reference

#aggregate

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

13 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.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Calculate Averages With AVG

Compute the arithmetic mean of numeric values across matching rows.

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.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Count Rows With COUNT(*)

Aggregate a result set into a single row that reports how many rows matched.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Count Unique Values With COUNT DISTINCT

Count only the distinct values in a column, ignoring duplicates.

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.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Find The Smallest And Largest Values With MIN And MAX

Use `MIN` and `MAX` to find the lowest and highest values in a column.

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.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Total Values With SUM

Add numeric values across matching rows and return one aggregate total.

beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Understand COUNT(column) Versus COUNT(*)

`COUNT(column)` skips `NULL` values, while `COUNT(*)` counts every row that made it into the result set.