How can I collect only the first and last mark, where an official can have X Markings and even markings the next day?
As the example below
+------+--------+-------+-------+
| FUNC | DATA |ENTRADA| SAIDA |
+------+--------+-------+-------+
|000001|20180901| 07.20 | 17.20 |
|000001|20180902| 07.20 | 17.20 |
|000001|20180903| 07.20 | 17.20 |
|000001|20180904| 07.20 | 01.00 |
|000001|20180905| 07.20 | 16.00 |
|000001|20180906| 05.00 | 17.00 |
+------+--------+-------+-------+
Note: the information I want to get is this, will it?
Data
Text Data
+------+--------+-----+----+--------+
| FUNC | DATA |HORA | TM |DATAAPO |
+------+--------+-----+----+--------+
|000001|20180901|07.20| 1E |20180901|
|000001|20180901|17.20| 1S |20180901|
|000001|20180902|07.20| 1E |20180902|
|000001|20180902|12.00| 1S |20180902|
|000001|20180902|13.00| |20180902|
|000001|20180902|17.20| |20180902|
|000001|20180903|07.20| 1E |20180903|
|000001|20180903|12.00| 1S |20180903|
|000001|20180903|13.00| 2E |20180903|
|000001|20180903|17.20| |20180903|
|000001|20180904|07.20| |20180904|
|000001|20180905|01.00| 1S |20180904|
|000001|20180905|07.20| 1E |20180905|
|000001|20180905|16.00| |20180905|
|000001|20180906|05.00| |20180906|
|000001|20180906|12.00| 1S |20180906|
|000001|20180906|13.00| |20180906|
|000001|20180906|17.00| 2S |20180906|
+------+--------+-----+----+--------+
Note: Remember that on some occasions the TM is not filled with the information of 1st and / or 2nd (Exit or Entry)
Data in SQL Format
CREATE TABLE FUNC (
pFUNC varchar(6),
pNOME varchar(100)
);
insert into FUNC (pFUNC, pNOME) values
('000001','FULANO'),
('000002','BELTRANO'),
('000003','SICLANO')
CREATE TABLE PONTO (
pFUNC varchar(6),
pDATA varchar(8),
pHORA float,
pTM varchar(2),
pDTAPO varchar(8)
);
insert into PONTO (pFUNC, pDATA, pHORA, pTM, pDTAPO) values
('000001','20180901', 7.20,'1E','20180901'),
('000001','20180901',17.20,'1S','20180901'),
('000001','20180902', 7.20,'1E','20180902'),
('000001','20180902',12.00,'1S','20180902'),
('000001','20180902',13.00,' ','20180902'),
('000001','20180902',17.20,' ','20180902'),
('000001','20180903', 7.20,'1E','20180903'),
('000001','20180903',12.00,'1S','20180903'),
('000001','20180903',13.00,'2E','20180903'),
('000001','20180903',17.20,' ','20180903'),
('000001','20180904', 7.20,' ','20180904'),
('000001','20180905', 1.00,'1S','20180904'),
('000001','20180905', 7.20,'1E','20180905'),
('000001','20180905',16.00,' ','20180905'),
('000001','20180906', 5.00,' ','20180906'),
('000001','20180906',12.00,'1S','20180906'),
('000001','20180906',13.00,' ','20180906'),
('000001','20180906',17.00,'2S','20180906')
Data in SQLFiddle
Any questions just ask ...