From the course: MySQL Data Analysis

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

HAVING example

HAVING example

- [Instructor] Okay, let's talk a little bit more about the having clause and then we'll get into an example. So, having is an optional clause and you use it with group by. When you do this, you can limit your result set just to the groups which satisfies certain logical criteria. Having always comes after the group by and before the order by if you have an order by. We'll talk about order by later in the course. Here's a query so you can see how the syntax works. We've got a select with customer ID and an aggregate function to count the total number of rentals for that customer from the rental table and we're grouping it by customer ID. So that part should be familiar to you at this point. Now, this next part having count star greater than or equal to 30, is going to filter down our data set to only include customers who have a count of rentals greater than or equal to 30. Let's get into Workbench and go through some examples. Alright, this query should look pretty familiar. Here…

Contents