Eu tenho duas mesas:
things
:+------+----------------+------------+ | id | current_status | created_at | +------+----------------+------------+ | 7770 | active | 2016-08-09 | +------+----------------+------------+
thing_status_tract
:+----------+-------------+-----------+---------------------+ | thing_id | status_from | status_to | changed_at | +----------+-------------+-----------+---------------------+ | 7770 | incomplete | inactive | 2016-08-09 16:26:22 | | 7770 | inactive | active | 2016-08-10 12:31:04 | +----------+-------------+-----------+---------------------+
Preciso de dados no seguinte formulário. Esta tabela tem um status e seu carimbo de data/hora inicial e final correspondente para um determinado thing_id
:
+----------+-------------+---------------------+---------------------+
| thing_id | status | status_start_date | status_end_date |
+----------+-------------+---------------------+---------------------+
| 7770 | incomplete | 2016-08-09 00:00:00 | 2016-08-09 16:26:22 |
| 7770 | inactive | 2016-08-09 16:26:22 | 2016-08-10 12:31:04 |
| 7770 | active | 2016-08-10 12:31:04 | now() |
+----------+-------------+---------------------+---------------------+
Como fazer isso com uma consulta SQL?