Answer the question
In order to leave comments, you need to log in
T-SQL - get previous value How?
Hey!
There is a model field. How to write a code in t-sql, what function can be used to get the values as in the parent_model field? That is, for each value of model, its parent value is needed.
thanks for any hints.
Answer the question
In order to leave comments, you need to log in
Use window functions LAG, LEAD:
SELECT model, LAG(model, 1,0) OVER (ORDER BY model ) as parent_model
FROM [mytable]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question