I have the following table
| TransactionID | UserID | TransactionDateTime |
|---|---|---|
| 1 | 1 | '2021-04-22 11:00:00' |
| 2 | 2 | '2021-04-22 11:00:11' |
| 3 | 1 | '2021-04-22 11:00:22' |
| 4 | 3 | '2021-04-22 11:00:33' |
| 5 | 3 | '2021-04-22 11:00:44' |
| 6 | 1 | '2021-04-22 11:00:55' |
I want to see the time difference between transactions for each UserID. Something like this:
| TransactionID | UserID | TransactionDateTime | TimeDifference |
|---|---|---|---|
| 1 | 1 | '2021-04-22 11:00:00' | NULL |
| 2 | 2 | '2021-04-22 11:00:11' | NULL |
| 3 | 1 | '2021-04-22 11:00:22' | 00:22 |
| 4 | 3 | '2021-04-22 11:00:33' | NULL |
| 5 | 3 | '2021-04-22 11:00:44' | 00:11 |
| 6 | 1 | '2021-04-22 11:00:55' | 00:33 |
Is there any possible way to do that?
https://dbfiddle.uk/?rdbms=mysql_5.5&fiddle=b7d43521afc8fe6623f152343bb88d4b