SQL Tutorial 5 : “HAVING” Function

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)
FROM world
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.

Next : SQL Tutorial 6 : “JOIN” Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s