0

I don't know if it's possible if I could do this:

I have this table:

Customer Week SoldUnits
C1 1 24
C1 2 17
C1 3 52
C2 1 18
C2 2 65
C2 3 12
C2 4 33
C3 1 18
C3 2 65

And I want to calculate the average of the last 2 weeks available of every customer. For example, I have to return this table:

Customer AverageSoldUnits
C1 34.5
C2 22.5
C3 41.5

The trick is that not every customer has the same max Week.

NHW
  • 13
  • 2
  • Please elaborate on your MySql verion – Stu Apr 20 '22 at 22:11
  • So you just need to know how to get the last two rows for each customer, right? Once you do that, you just use `AVG()` and `GROUP BY Customer` – Barmar Apr 20 '22 at 22:13

0 Answers0