Click here to navigate the course.

Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor

Query Results

Run a query to see results.

Database Schema

Schema undefined.
Advanced Aggregates

Grouping with Case Statements

To see if our smoothie suspicion has merit, let's look at purchases by category. We can group the order items by what type of food they are, and go from there. Since our order_items table does not include categories already, we'll need to make some!

Previously we've been using group by with a column (like or a function (like date(orders.ordered_at)).

We can also use group by with expressions. In this case a case statement is just what we need to build our own categories. case statements are similar to if/else in other languages.

Here's the basic structure of a case statement:

case {condition} when {value1} then {result1} when {value2} then {result2} else {result3} end
Report a Bug
If you see a bug or any other issue with this page, please report it here.