I have a table as below
ID | DateTime | Summary |
---|---|---|
1 | 2022-06-21 19:03:30.783 | XSR |
1 | 2022-06-21 19:04:40.763 | GKE |
1 | 2022-06-21 19:05:35.483 | ERE |
2 | 2022-07-20 11:01:20.783 | BMR |
2 | 2022-07-20 12:03:39.142 | PER |
It should produce an output as below. ie start datetime and end datetime of every ID. Also output the end time's Summary value.
Expected Result:
ID | Start DateTime | End DateTime | Summary |
---|---|---|---|
1 | 2022-06-21 19:03:30.783 | 2022-06-21 19:05:35.483 | ERE |
2 | 2022-07-20 11:01:20.783 | 2022-07-20 12:03:39.142 | PER |
Code I tried
select MIN (t1.DateTime) as StartTime, MAX (t1.DateTime) as EndTime, datediff(MINUTE, min(t1.DateTime), max(t1.DateTime)) as 'RunTime (Mins)'
,max (t1.Summary)
from table t1