课程: SQL Hands-On Practice: Solve Business Problems

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Get running totals with window functions

Solution: Get running totals with window functions - SQL教程

课程: SQL Hands-On Practice: Solve Business Problems

Solution: Get running totals with window functions

- [Instructor] Calculating running totals in SQL is another really common interview question, so this is a really good concept to know. For this problem, we need to calculate the running total of the Sale Amount column over time for each sales rep. Then we will divide this by the quota amount to update the percent quota reached after each sale. Let's start with the basics of the query first. We'll need to join the Employees table to the Sales table so we can pull in the quota for each sales employee. We're going to start with select. And we'll start with star just as a placeholder for now. And we're going to pull data from the Sales table. Let's call it s for short. Then we're going to join the Employees table. And we'll call that table e. And we're going to join these tables on the sales employee ID equals the employee ID. And we're going to order by the sales employee ID and the sale date. That way we can easily…

内容