• Could you use something like this?

    If it works, do you understand it?

    ;WITH CTE AS(

    selectcalcid,

    salesamount,

    productid,

    ROW_NUMBER() OVER( PARTITION BY productid ORDER BY calcid) rn

    from #abc t1

    --where productid IN (58, 62, 65)

    )

    SELECTcte1.productid,

    cte1.calcid,

    cte1.salesamount,

    cte2.calcid AS prevcalcid,

    cte2.salesamount AS prevsalesamount

    FROM CTE cte1

    LEFT

    JOIN CTE cte2 ON cte1.productid = cte2.productid

    AND cte1.rn = cte2.rn + 1

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2