January 2019
Beginner
556 pages
14h 19m
English
Aggregating functions are not allowed in the WHERE clause, but it's possible to filter groups that follow a certain condition. This is different from filtering in the WHERE clause, because WHERE filters input rows, and groups are calculated afterward.
The filtering of groups is done in the HAVING clause. This is very similar to the WHERE clause, but only aggregating functions are allowed there. The HAVING clause is specified after the GROUP BY clause. Suppose you need to know which models have more than 5 cars entered in the system. This can be done using a subquery:
car_portal=> SELECT make, model FROM( SELECT make, model, count(*) c FROM car_portal_app.car a INNER JOIN car_portal_app.car_model b ON a.car_model_id=b.car_model_id ...
Read now
Unlock full access