I have a table where I record the time when a given request had its status_id
changed. This table I call historico_status_solicitacoes
.
In this table, I have the following fields: id
, status_id
, solicitacao_id
, usuario_id
, created_at
.
For each request that has changed status, a record is entered.
So:
+----+-----------+----------------+------------+---------------------+
| id | status_id | solicitacao_id | usuario_id | created_at |
+----+-----------+----------------+------------+---------------------+
| 1 | 1 | 1 | 1 | 2018-10-29 17:28:46 |
| 2 | 2 | 1 | 1 | 2018-10-29 17:38:50 |
| 3 | 3 | 1 | 1 | 2018-10-29 17:48:16 |
| 4 | 4 | 1 | 1 | 2018-10-29 18:58:46 |
| 5 | 5 | 1 | 1 | 2018-10-29 19:31:46 |
| 6 | 6 | 1 | 1 | 2018-10-30 10:20:00 |
+----+-----------+----------------+------------+---------------------+
What do I need to do? I need to make a query, where I can compute the difference in minutes between one row and another, considering the smallest date for the largest date (which in this case can be id
also, since it is created sequentially, and the largest value is always the most recent).
I've done something similar to calculate the current balance, using the previous line, but I have no idea how to work with time difference in MYSQL.
Can anyone help?