Du har brug for en forespørgsel som denne. Sørg for at inkludere NULL
kontrollerer for Data1 ,Data2, når der mangler poster for fremtidige datoer eller tidligere datoer og standard det til nul, hvis det er nødvendigt.
select To_CHAR(Month,'MON-YY') Month,
CASE
WHEN MOD ( EXTRACT ( MONTH FROM Month ), 3 ) = 1
THEN Data2 + LEAD ( Data2 ,1) OVER ( ORDER BY Month ) + LEAD ( Data2 ,2) OVER ( ORDER BY Month )
WHEN MOD ( EXTRACT ( MONTH FROM Month ), 3 ) = 2
THEN LAG(Data1,1) OVER ( ORDER By Month ) + Data2 + LEAD ( Data2 ,1) OVER ( ORDER BY Month )
WHEN MOD ( EXTRACT ( MONTH FROM Month ), 3 ) = 0
THEN LAG(Data1,2) OVER ( ORDER By Month ) + LAG(Data1,1) OVER ( ORDER By Month )+Data2
END data
FROM
Table1;