I need help please.
In my final select I want to display the next row's value in PriceValue
column
Example of my stored procedure:
SELECT
w.ShopID AS shopID,
w.ProductName AS ProductName,
w.ProductID AS ProductID,
w.PriceValue -- (this logic should be: if w.Type = Outdoor then give the next row's value
-- which would then be **100 000** and **90 000** see image)
FROM
Warehouse w
Thank you!
CodePudding user response:
You can use LEAD() (for previous LAG()) function there. ie:
SELECT w.ShopID as shopID, w.ProductName as ProductName,
w.ProductID as ProductID,
w.ProductID as w.PriceValue,
case when Type = 'Outdoor' then
Lead(PriceValue, 1, 0) over (Partition by ProductName order by ProductId) else PriceValue end as ModifiedPrice
from myTable;
Note: Your data structure looks weird, that may be a typo.