Chapter 6. Advanced SELECT: Sorting and Aggregating
It’s time to take your SELECT to new heights. You already know how to SELECT data and use WHERE clauses. But sometimes your queries need a little more altitude than what SELECT and WHERE can achieve alone.
In this chapter, you’ll learn how to sort your data in multiple ways. You’ll build mathematical calculations and aggregate values. And in CASE you need new categories, you’ll learn how to pull the rip cord with if-then-else logic for your own classifications. Make the SELECT jump and here we go!
Shopping around
Since the last chapter ended, your pal Josh has been busy, very busy.
Here’s a snippet of the stores table. Josh just inserted rows in whatever order he visited the businesses.
ORDER (BY) in the court!
You say you need to order your query? Well, it just so happens that you can tell SQL to SELECT something and ORDER the data it returns BY a column from your table.
Here’s how Josh can retrieve all the businesses in alphabetical ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access