0
I have the following appointment:
SELECT *
FROM SERQUENCIAL
WHERE DATA BETWEEN '2017-01-01' AND '2017-01-19'
She returns:
+--------------+-------+------------+-----------------------+
| ID_PESS NOME | DATA | DATA_HORA | SEQUENCIAL |
+--------------+-------+------------+-----------------------+
| 8788 | JOAO | 2017-01-01 | 2017-01-01 13:01:01 1 |
| 8788 | JOAO | 2017-01-01 | 2017-01-01 15:07:01 2 |
| 8788 | JOAO | 2017-01-01 | 2017-01-01 17:08:01 3 |
| 8788 | JOAO | 2017-01-01 | 2017-01-01 19:03:01 4 |
| 8533 | MARIA | 2017-01-03 | 2017-01-03 11:01:01 1 |
| 8533 | MARIA | 2017-01-03 | 2017-01-03 14:07:01 2 |
| 8533 | MARIA | 2017-01-03 | 2017-01-03 16:08:01 3 |
| 8533 | MARIA | 2017-01-03 | 2017-01-03 18:03:01 4 |
| 8935 | JOSE | 2017-01-05 | 2017-01-05 13:01:01 1 |
| 8935 | JOSE | 2017-01-05 | 2017-01-05 19:07:01 2 |
| 8935 | JOSE | 2017-01-05 | 2017-01-05 20:08:01 3 |
| 8935 | JOSE | 2017-01-05 | 2017-01-05 22:03:01 4 |
| 8935 | JOSE | 2017-01-05 | 2017-01-05 23:03:01 5 |
+--------------+-------+------------+-----------------------+
How do I join the returns per person in the following way for example:
+---------+------+------------+---------------------+------+---------------------+------+---------------------+------+---------------------+------+
| ID_PESS | NOME | DATA | DATA_HORA_01 | SEQ1 | DATA_HORA_02 | SEQ2 | DATA_HORA_03 | SEQ3 | DATA_HORA_04 | SEQ4 |
+---------+------+------------+---------------------+------+---------------------+------+---------------------+------+---------------------+------+
| 8788 | JOAO | 2017-01-01 | 2017-01-01 13:01:01 | 1 | 2017-01-01 15:07:01 | 2 | 2017-01-01 17:08:01 | 3 | 2017-01-01 19:03:01 | 4 |
+---------+------+------------+---------------------+------+---------------------+------+---------------------+------+---------------------+------+
That is, the data of the person together on the same line.
Observing:
The person’s data can be repeated on another day. If it happens it will be a new line of the person.
It would not be possible to use the
Group by
in the columnID_PESS
– R.Santos
Not because there will join and would not list the other fields date and sequential
– Chefe Druida
Some questions, can Sequential be broken into two fields? One with the date and the other with the increment? This final number is generated as, from the application?
– gmsantos