Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Calculate Running Total of Sales | Introduction to Window Functions
Window Functions in SQL

bookChallenge: Calculate Running Total of Sales

Uppgift

Swipe to start coding

Write a query to calculate the running total of sales amount for each employee, ordered by sale_date.

  • For each row in the sales table, calculate a running total of the amount for the same employee_id.
  • The running total should be ordered by sale_date. If two sales have the same date for the same employee, use sale_id to break ties.
  • The output should include columns: sale_id, sale_date, employee_id, amount, and the calculated running total as running_total.
  • The results should be ordered by employee_id, then by sale_date, then by sale_id.

Lösning

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 2
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you explain this in simpler terms?

What are the main points I should remember?

Can you give me an example?

close

bookChallenge: Calculate Running Total of Sales

Svep för att visa menyn

Uppgift

Swipe to start coding

Write a query to calculate the running total of sales amount for each employee, ordered by sale_date.

  • For each row in the sales table, calculate a running total of the amount for the same employee_id.
  • The running total should be ordered by sale_date. If two sales have the same date for the same employee, use sale_id to break ties.
  • The output should include columns: sale_id, sale_date, employee_id, amount, and the calculated running total as running_total.
  • The results should be ordered by employee_id, then by sale_date, then by sale_id.

Lösning

Switch to desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 2
single

single

some-alt