From the course: Complete Your First Project in SQL

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Average daily sales

Solution: Average daily sales - SQL Tutorial

From the course: Complete Your First Project in SQL

Solution: Average daily sales

(upbeat music) - [Instructor] Welcome back. Excellent work on finding out the average daily sales. If this challenge felt overwhelming, don't worry. I will walk you through the code step-by-step to explain how to accomplish this task. So if we head over to Codespaces, you can begin your code by using a SELECT statement and then jump right in to creating your average daily sales column. For this one, you'll want to use the SUM function on the quantity column to gather the total number of items sold. Then you will be dividing this by the days. For this column, you'll want to use the COUNT function on the creation date column, but make sure you add in DISTINCT to ensure you only count each date once. This will gather the distinct number of days where at least one item was sold. You can alias this new column as AverageDailySales. You'll gather this data from the Orders table and then do a LEFT OUTER JOIN on the OrderItem table. For these two tables, you will join them on their OrderID…

Contents