The sel_group.sql command file
The following example command file includes the GROUP BY and HAVING clauses. The HAVING clause usually complements a GROUP BY clause by applying one or more qualifying conditions to groups after they are formed, which is similar to the way the WHERE clause qualifies individual rows. (One advantage to using a HAVING clause is that you can include aggregates in the search condition; you cannot include aggregates in the search condition of a WHERE clause.)
Each
HAVING clause compares one column or aggregate expression of the group
with another aggregate expression of the group or with a constant.
You can use the HAVING clause to place conditions on both column values
and aggregate values in the group list.
SELECT order_num, COUNT(*) number, AVG (total_price) average
FROM items
GROUP BY order_num
HAVING COUNT(*) > 2;