I would like to get the data from previous row. I have used LAG function but did not get the expected result.
Table:-
col1 col2 col3 ABCD 1 Y ABCD
Use lag() function
lag()
select *, lag(col3) over (partition by col1 order by col2) as col4 from table t;
However You can also use subquery if your SQL doesn't have LAG()
subquery
SQL
LAG()
select *, (select top 1 col3 from table where col1 = t.col1 and col2 < t.col2 order by col2 desc ) as col4 from table t;