Group by Clause in SQL
The GROUP BY
clause in SQL is used to group rows that have the same values in specified columns into summary rows. It is typically used with aggregate functions like SUM
, COUNT
, AVG
, etc., to perform calculations on grouped data. When using GROUP BY
, rows are divided into groups based on the unique values of the specified column(s). The result set will then contain one row for each group, with aggregated values computed from the grouped rows. This allows for summarizing and analyzing data at different levels of granularity, providing insights into patterns and distributions within the dataset.