Currently I have a table with the following values:
some-id timestamp modified_by other_info
--------- ----------- ------------- ------------
1 12:45 person_1 misc
1 12:50 person_5 stuff
2 3:13 robot_1 things
2 3:15 random_1 more
3 11:33
3 11:50
I would like a resulting SELECT
to return the below:
some-id duration start_person end_person other_info
--------- ------------- -------------- -------------- --------------
1 5 person_1 person_5 misc
2 2 robot_1 random_1
3 17
eg. The timestamp
is grouped by a duplicate some_id
. I want to display the duration of the some_id
as well as the value of what user is linked with the respective timestamp.
I am able to create the table with duration, but trying to figure out how to include start_person
and end_person
SELECT some-id, TIMESTAMP_DIFF(MAX(timestamp), MIN(timestamp), MILLISECOND) as duration
FROM t
GROUP BY some-id