3
How can I gather only the first and last appointment, where a staff member can have X Appointments and even appointments 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 the ?
Dice
Data in Text
+------+--------+-----+----+--------+
| 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: Remembering that in some occasions the TM is not filled with the information of 1º and/ or 2º (Output or Input)
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
http://sqlfiddle.com/#! 18/f9f25/2
Any doubt just ask...
What is the difference between the pDATA and pDTAPO columns? Could explain what happened on days 4 and 5?
– José Diz
pData is the date on which the marking was made, pDTAPO is the date on which the marking should be considered...
– Roberto Valentim