Group By and Having
The group by clause is used to group records by an attribute/set of attributes. An aggregate operation (count, max, min, avg etc.) can be performed after grouping.
Note that all the attributes in the select clause (that aren't part of an aggregate function) must be present in the group by clause.
is an erroneous query because ID isn't in the group by clause (salary can be exempted because it is part of the avg aggregate function).
The having clause is a predicate for grouping.
Note that the where clause is applied before grouping and the having clause is applied after grouping.
Last updated