May 2020
Beginner
564 pages
14h 9m
English
Let's say you needed to see the results of running the GROUP BY clause in the previous section, but where the sum of at-bats is greater than 100. This is when you would use a HAVING clause, as shown in the following query:
USE lahmansbaseballdb; SELECT playerid, teamid, sum(AB) AS sum_at_batsFROM batting GROUP BY playerid, teamid HAVING sum_at_bats > 100;
The following screenshot shows the results of running the previous query:

Here, you can see the results of GROUP BY, with only the sum of at-bats that are greater than 100.
Let's say you were using a WHERE clause for this instead, ...
Read now
Unlock full access