Skip to content
Advertisement

Difference between data of two different row belonging to two different columns in SQL

Sample Table:

I need a column which calculates the time difference of Free time of a day. Example for Pallavi on 7/5/2020 between first customer out time and second customer in time that is 75 mins and if there is only a single customer for a day then the output for that waiter for that day is 0.

Advertisement

Answer

Use lag() to get the previous out time and then aggregate:

In older, unsupported versions of SQL Server, you can use apply:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement