Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: 7-Day Moving Average of Sales | Introduction to Window Functions
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Window Functions in SQL

bookChallenge: 7-Day Moving Average of Sales

Oppgave

Swipe to start coding

Write a query to calculate the 7-day moving average of the amount for each employee_id, ordered by sale_date.

  • Use a window function to partition the data by employee_id.
  • Order the rows within each partition by sale_date.
  • Compute the average of amount for the current row and the previous 6 rows within the partition.
  • Output the columns: sale_id, sale_date, employee_id, amount, and the calculated 7-day moving average as moving_avg_7d.
  • Order the final results by employee_id and sale_date.

Løsning

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 6
single

single

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

close

bookChallenge: 7-Day Moving Average of Sales

Sveip for å vise menyen

Oppgave

Swipe to start coding

Write a query to calculate the 7-day moving average of the amount for each employee_id, ordered by sale_date.

  • Use a window function to partition the data by employee_id.
  • Order the rows within each partition by sale_date.
  • Compute the average of amount for the current row and the previous 6 rows within the partition.
  • Output the columns: sale_id, sale_date, employee_id, amount, and the calculated 7-day moving average as moving_avg_7d.
  • Order the final results by employee_id and sale_date.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 6
single

single

some-alt