From the course: SQL Practice: Window Functions

Unlock this course with a free trial

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

Solution: Compare order totals over time

Solution: Compare order totals over time - SQL Tutorial

From the course: SQL Practice: Window Functions

Solution: Compare order totals over time

- [Instructor] In this solution, I'm using CTE or common table expression notation to save some typing, because this challenge requires joining across three tables. You don't have to, though. I just think it makes things easier to type and to read. Let's start in the middle of the query and work toward the end. I start out here by selecting from the orders table, which I've named O, and then I joined the orders dishes table, which I'm calling OD to it, so that the order ID on the orders table matches up with the order ID on the orders dishes table. That lets us associate the items in an order with the order they belong to. Then I join the dishes table, which I'm calling D, so that the dish ID field on the dishes table matches up with a dish ID field on the orders dishes table. This way, I associate the dishes contained in each order, and most importantly for our challenge, I can get the price of each dish in each order.…

Contents