waar id<=14
(dat is t2.id <= t1.id
zoals hieronder getoond) dus wanneer t1 id =14
, t2
is de cumulatieve id van 1 tot 14 (zoals het nu is).
Update t join
(
SELECT t1.id ,ifnull(t1.A/AVG(t2.A),0) C ,ifnull(t1.B/AVG(t2.B),0) D
FROM t t1
JOIN t t2
ON case when t2.id < 15 then t2.id <= t1.id else t2.id=t1.id>=t1.id-2 and <=t1.id end
group by t1.id
) tt on(t.id = tt.id)
SET E = (tt.C + tt.D)/2;