MySQL groupby time time difference
If you want to find the date/time difference between the first and the last timestamp of each ticket, there are several functions that can help you:

select 
    ticket_id,
    timediff(max(timestamp), min(timestamp))              as diff,
    timestampdiff(hour, min(timestamp), max(timestamp))   as diff_in_hours,
    timestampdiff(minute, min(timestamp), max(timestamp)) as diff_in_minutes,
    timestampdiff(second, min(timestamp), max(timestamp)) as diff_in_seconds
from tickets
group by ticket_id ;


Test in dbfiddle.uk:




select ticket_id,
       timediff(max(timestamp), min(timestamp)) as diff,
       timestampdiff(hour, min(timestamp), max(timestamp)) as diff_in_hours,
       timestampdiff(minute, min(timestamp), max(timestamp)) as diff_in_minutes,
       timestampdiff(second, min(timestamp), max(timestamp)) as diff_in_seconds
from tickets
group by ticket_id ;



 ticket_id | diff      | diff_in_hours | diff_in_minutes | diff_in_seconds
---------: | :-------- | ------------: | --------------: | --------------:
1466089815 | 263:01:00 |           263 |           15781 |          946860
1466089816 | 263:36:00 |           263 |           15816 |          948960