0

Recently got my golden certificate for completing SQL Server Implementation... I am officially allowed to add 1 and 1. Still a noob and need some serious help :-).

I have really tried hard to find the solution to this, previously using DAX in Excel it work out perfectly.

Table with Refueling Transactions: File (Source Information); FleetNo_PT (Asset Number); Date_Refuel; Quantity; Reading (KM_Odometer)

Requirement: Show Current and Previous Transaction Information on a Single Line AND then calculated results Days Between Refueling; KM_Driven; Consumption_Rate (KM_Driven divide by Quantity)

I have tried many different way but non are successful

  • Does the row have a createdAt field or a identity column? You could use those to get the latest: https://stackoverflow.com/questions/9477502/get-the-last-inserted-row-id-with-sql-statement – MaartenDev Jul 17 '22 at 13:13
  • @maartenDev,That did not solve my problem, in fact that whole thing created more confusion – Anthony Norman Jul 18 '22 at 06:11
  • The real solution here is LEAD and LAG function, its far simpler solution than the proposed solution. To attain the previous or next transaction detail use https://www.youtube.com/results?search_query=sql+previous+transaction+value – Anthony Norman Jul 18 '22 at 08:47

0 Answers0