

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: What Are Aggregations?
incomplete
2: SUM
incomplete
3: MAX
incomplete
4: MIN
incomplete
5: GROUP BY
incomplete
6: Average
incomplete
7: HAVING
incomplete
8: HAVING vs. WHERE in SQL
incomplete
9: ROUND
incomplete
10: Query Practice – Average Ages
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
When we need to filter the results of a GROUP BY query even further, we can use the HAVING clause. HAVING specifies a search condition for a group.
The HAVING clause is similar to the WHERE clause, but it operates on groups after they've been grouped, rather than rows before they've been grouped.
SELECT album_id, COUNT(id) AS count
FROM songs
GROUP BY album_id
HAVING COUNT(id) > 5;
This query returns the album_id and count of its songs, but only for albums with more than 5 songs.
A new page in the CashPal app allows users to see how much money they've spent on a specific kind of transaction, and alerts them if that amount is fairly large. Let's write a query on the transactions table that returns the total amount spent by each user on lunch when that balance is greater than 20.
Your query should: