Share via

Getting rate change

-- -- 957 Reputation points
2023-08-30T08:26:42.9533333+00:00

Hi

We have two tables Orders (OrderID, OrderDate, ClientID) and OrderProducts (ID, OrderID, ProductID, Amount).

How can we use T-SQL to find for each client the last two rates (Amount column) for each product and the dates they were first used in orders? Basically we are trying to find rate changes for each product for each client over time.

We need output like below grouped by client and then product.

ClientID, ProductID, Last Rate (Amount), Order Date Last Rate First Used, Current Rate (Amount), Order Date Current Rate First Used

Thanks

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.