HAVING

Used with GROUP BY because the WHERE keyword cannot be used with aggregate functions.

 

To find all customers HAVING a total expenditure greater than 2000:

mysql> select CustID, sum(Qty*Cost) AS Total from orders group by CustID having sum(qty*cost) > 2000;
+--------+-------+
| CustID | Total |
+--------+-------+
|      2 |  4786 |
|      3 |  5614 |
+--------+-------+
2 rows in set (0.00 sec)

Leave a Reply