Mysql horizontalizing grouping I have a table that essentially has rows with:

sessionId
date/time
event


event can be (to make it simple, "start" and "end")

The same sessionId however can be reused, so, simply I have

sessionId     datetime                event
AAAAA         2020-01-01 11:30:00     start
AAAAA         2020-01-01 12:20:00     end
AAAAA         2020-01-01 14:22:00     start
AAAAA         2020-01-01 14:30:00     end
BBBBB         2020-01-02 14:22:00     start
BBBBB         2020-01-02 14:42:00     end
CCCCC ...etc ...


I need to convert it to:

SessionId     StartTime              duration
AAAAA         2020-01-01 11:30:00     00:50:00
AAAAA         2020-01-01 14:22:00     00:08:00
BBBBB         2020-01-02 14:22:00     00:20:00


Is there any way I can do this with an sql query or do I have to do it in code?

Thanks in advance!
SELECT t1.sessionId, t1.dt StartTime, TIMEDIFF(t2.dt, t1.dt) duration
FROM src t1
JOIN src t2 ON t1.event = 'start'
           AND t2.event = 'end'
           AND t1.sessionId = t2.sessionId
           AND t1.dt &lt; t2.dt
           AND NOT EXISTS ( SELECT NULL
                            FROM src t3
                            WHERE t3.sessionId = t1.sessionId
                              AND t1.dt &lt; t3.dt
                              AND t3.dt &lt; t2.dt );


fiddle