

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
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
An "aggregation" is a single value that's derived by combining several other values. We performed an aggregation earlier when we used the COUNT statement to count the number of records in a table.
Data stored in a database should generally be stored raw. When we need to calculate some additional data from the raw data, we can use an aggregation.
Take the following COUNT aggregation as an example:
SELECT COUNT(*)
FROM products
WHERE quantity = 0;
This query returns the number of products that have a quantity of 0. We could store a count of the products in a separate database table, and increment/decrement it whenever we make changes to the products table – but that would be redundant.
It's much simpler to store the products in a single place (we call this a single source of truth) and run an aggregation when we need to derive additional information from the raw data.
The front-end team is building a dashboard page in CashPal. We need to be able to provide them the number of successful transactions for a given user.
Return the number of transactions where the user_id is 6 and was_successful is true. (Remember to use the * wildcard unless otherwise specified to pass the lesson.)