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

bookChallenge: Calculate Running Total of Sales

Opgave

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 alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

bookChallenge: Calculate Running Total of Sales

Stryg for at vise menuen

Opgave

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 desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2
single

single

some-alt