GROUP BY¶
The GROUP BY
groups rows that have the same values in specified columns into summary rows, like aggregating data.
Syntax¶
SELECT <column1>, [ aggregate_function <column2> ]
FROM <table_name>
[ WHERE <condition> ]
GROUP BY <column_name>
Arguments¶
Parameter |
Description |
---|---|
|
The column by which you want to group the data |
|
The columns to retrieve |
|
The table from which to retrieve the data |
|
Filters the rows before grouping them |
|
Groups the rows by the values in column1 |
Examples¶
SELECT
department_id,
COUNT(*)
FROM
employees
GROUP BY
department_id;