Why is there a error when I try to rename a column after the over clause?

32 views Asked by At

I want to rename a column after calculating the difference between current row and previous row by using over clause (windows function)

However, I cannot run it and it shows that I have a error in my sql syntax

select country,year,
avg(oil_consumption) OVER (partition by country 
  order BY year 
     ROWS BETWEEN 2 PRECEDING AND current row )
     as 3_year_moving_average, (3_year_moving_average-lag(3_year_moving_average,1) over (partition by country) **as** difference_between_previous_current
from owid_energy_data

Error at the second as (bolded)

0

There are 0 answers