# GROUP BY Clause
__*The role of aggregate functions*__
__*GROUP BY operation*__
__*ONLY_FULL_GROUP_BY SQL mode pattern*__
+ Grouping rows for aggregation
+ **`ONLY_FULL_GROUP_BY`** SQL mode
  + If a column appears in the **`SELECT`** list that does not appear in **`GROUP BY`** or in an aggregate function, the `SQL` statement is invalid
```8
tidb> SELECT
    -> ring_systems, 
    -> COUNT(name), SUM(mass)
    -> FROM universe.planets
    -> GROUP BY ring_systems;
+--------------+-------------+--------------------+
| RING_SYSTEMS | COUNT(name) | SUM(mass)          |
+--------------+-------------+--------------------+
|            0 |           6 | 19.406899828463793 |
|            1 |           4 |  2654.800003051758 |
+--------------+-------------+--------------------+
2 rows in set (0.00 sec)

tidb> SELECT ring_systems, ~!@CATEGORY_ID@!~, COUNT(*) FROM universe.planets GROUP BY ring_systems;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'universe.planets.category_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
```

------------------------------------------------------------

```
tidb> SELECT ring_systems, category_id, COUNT(*) FROM universe.planets GROUP BY ring_systems;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'universe.planets.category_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

tidb> SELECT @@SQL_MODE;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@SQL_MODE                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
