We saw some of the group functions, which treats the table as one large group of information. At times we may want to divide the table of information into smaller groups. This can be done by using group by clause. The syntax is :
In the above syntax :
Column|expr specifies columns whose values determine the basis for grouping rows.
We can use the group by clause to divide the rows in a table into groups. We can then use the group function to return summary information for each group.
All columns in the select list that are not in group functions must be in the group by clause. Using a where clause we can exclude rows before dividing them into groups. We cannot use a column alias in the group by clause. By default rows are stored by ascending order of the columns included in the group by list. We can overwrite this by using the order by clause.
it is not necessary that the column we are using in group by clause should exist in the select list . it also possible to specify more than one column name in the group by clause. In that case the first column will be grouped first within that the second column will be grouped.