SQL Find difference between rows with unique IDs

  • A+
Category:Languages

I have a table with two rows, one has a start and one an end time with the same id.

For example

ID    | Time 12345 | 12-12-18 12:00 12345 | 12-12-18 12:12  54321 | 12-12-18 11:30 54321 | 12-12-18 11:35  

How would i go around getting the output

ID    | Time 12345 | 12 54321 | 5 

Guessing Lag or Over?

 


You seem to want an aggregation:

select id,        datediff(minute, min(time), max(time)) as diff_minutes from t group by id; 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: