0

I have a table like this:

MRLNum CreatedOn ReviseCode RequiredQty
SAN-000027-001 2/28/2023 0 100
SAN-000027-001 2/28/2023 1 30

This will list values by rowInt. How can get get the difference of Value between two rows with the result like this:

MRLNum CreatedOn ReviseCode RequiredQty ReviseCodePrvDiff RequiredQtyPrvDiff
SAN-000027-001 2/28/2023 0 100 NA NA
SAN-000027-001 2/28/2023 1 30 0 100

The table is in SQL 2017 (Miscrosoft)

wfxasb
  • 3
  • 4
  • Use [`lag()`](https://learn.microsoft.com/fr-fr/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver16), as shown in the most upvoted answer in the duplicate link for example. – GMB May 15 '23 at 07:55
  • mention link not resolved the problem please look into again – wfxasb May 15 '23 at 07:58
  • please, read the link until it resolves the problem - the LAG/LEAD functions were designed for these types of tasks. – Roasty Chips May 15 '23 at 09:03
  • You need a way to sort the rows for LAG/LEAD by some column(s) to work. In your example, what should one sort on ? ReviseCode? – siggemannen May 15 '23 at 11:57

0 Answers0