The “HAVING” function can be described as a WHERE function, but used for Aggregation functions.
For instance, a query which includes “WHERE sum(product_orders) > 10” will not work. Instead of using the WHERE function in such a scenario, the HAVING function will be used. (ie HAVING sum(product_orders) > 10)
To illustrate, let’s go back to our world_data dataset.
Consider the case where we only want to query continents with total gdp that is above 20000000000.
The following query will be used :
SELECT continent, SUM(gdp)
GROUP BY continent
HAVING SUM(gdp > 20000000000)
The output will be :
Before we move on to Topic 6, you can try doing a quiz here to test on your understanding thus far.