课程: SQL Hands-On Practice: Solve Business Problems
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
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…
内容
-
-
-
-
-
-
-
(已锁定)
Pulling the most recent sales data2 分钟 23 秒
-
(已锁定)
Rank(), row_number(), and dense_rank()2 分钟 55 秒
-
(已锁定)
Pulling the most recent sale with row_number()3 分钟 31 秒
-
(已锁定)
Introduction to window functions3 分钟 30 秒
-
(已锁定)
Solution: Get running totals with window functions6 分钟 22 秒
-
(已锁定)
Solution: Timestamp differences with LEAD()6 分钟 54 秒
-
(已锁定)
-