From the course: SQL Practice: Basic Queries

Unlock this course with a free trial

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

Solution: Find the average of orders

Solution: Find the average of orders - SQL Tutorial

From the course: SQL Practice: Basic Queries

Solution: Find the average of orders

- [Instructor] In this code challenge, you're asked to retrieve the average of all of the orders in this dataset. To do this, I'm going to use three tables, orders, dishes, and orders dishes as an intermediary table, because it has foreign keys to the other two tables. The initial code retrieves everything from the dishes table, and when I test that code, I see that there are 22 rows, and these are all the individual dishes. But if I select everything from orders dishes, I see that there are many more items, over 4,000, because there's a one to many relationship from order to dish. Here's my solution to this challenge. Notice that I have two select statements, one nested within the other, and I'm going to start with the nested select statement that retrieves the sum of all dishes for all orders. The nested select retrieves two columns, an order ID and the sum of the price from the dishes table. I'm joining the tables from…

Contents