Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: 7-Day Moving Average of Sales | Introduction to Window Functions
Window Functions in SQL

bookChallenge: 7-Day Moving Average of Sales

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 6
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain that in more detail?

What are the main benefits or drawbacks?

Can you give me an example?

close

bookChallenge: 7-Day Moving Average of Sales

Deslize para mostrar o menu

Tarefa

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.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 6
single

single

some-alt