Improve company productivity with a Business Account.Sign Up
CTE AS (
, row_number() over (partition BY TransNo ORDER BY TransDate ASC) AS rn
, CASE WHEN nxt.TransDate <> t.TransDate THEN nxt.rn ELSE NULL END AS diff_date
, CASE WHEN nxt.qty <> t.qty THEN nxt.rn ELSE NULL END AS diff_qtys
, CASE WHEN nxt.cost <> t.cost THEN nxt.rn ELSE NULL END AS diff_cost
FROM CTE AS t
LEFT JOIN CTE AS nxt ON t.TransNo = nxt.TransNo
AND (t.rn + 1) = nxt.rn --<< similar to lead
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Your question, your audience. Choose who sees your identity—and your question—with question security.