I have a table with 2 columns as shown below. Year and sales in that year
I Need to write a query which will display Average sales for a period of 2 years and same should be displayed for those 2 years for which sales is averaged.
Year Avg(sales)for 2 years
plese have a look on the below SQL .
SyntaxEditor Code Snippet
sel yr,case when (row_number () over (order by yr) )mod 2 =0 then avg(amount) over ( order by yr rows between 1 preceding and current row )else avg(amount) over ( order by yr rows between current row and 1 following )end as t from dev_test order by 1