I am not able to get the last value, rather it is just returning the same value with my code below in snowflake – does anyone have any idea? Is there something glaring wrong?
select MNTH, sum_cust, last_value(sum_cust) over (partition by MNTH order by sum_cust desc ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as sum_cust_last from block_2;
Advertisement
Answer
I think what you actually want is to LAG
the value from the previous MNTH
:
SELECT MNTH, sum_cust, LAG(sum_cust) OVER (ORDER BY MNTH) AS sum_cust_last FROM block_2;