0
Oracle-SQL
I have a chart that records the time records that each employee makes. The table contains the following information:
(TABELA QUE ESTOU FAZENDO A CONSULTA)
Contrato | Data | Hora
1 | 10/05/2018 | 07:00
1 | 10/05/2018 | 11:30
...
I must now transpose these columns, bringing these beats as columns (TABLE AS I WANT):
Contrato | Data | Hora 1 | Hora 2 | Hora 3 | Hora 4
Except I’m having a hard time getting the records, so look where I went: (QUERY CURRENT)
select distinct ponto.contrato CONTRATO,
ponto.datamarcacao DATA,
(select min(ponto1.horamarcacao)
from metaminu.rhmarcpontoreg ponto1
where ponto.contrato = ponto1.contrato
and ponto.datamarcacao = ponto1.datamarcacao) HORA1,
(select max(ponto2.horamarcacao)
from metaminu.rhmarcpontoreg ponto2
where ponto.contrato = ponto2.contrato
and ponto.datamarcacao = ponto2.datamarcacao) HORA2,
(select max(ponto3.horamarcacao)
from metaminu.rhmarcpontoreg ponto3
where ponto.contrato = ponto3.contrato
and ponto.datamarcacao = ponto3.datamarcacao) HORA3,
(select max(ponto4.horamarcacao)
from metaminu.rhmarcpontoreg ponto4
where ponto.contrato = ponto4.contrato
and ponto.datamarcacao = ponto4.datamarcacao) HORA4
from metaminu.rhmarcpontoreg ponto
where ponto.contrato = 7878
order by ponto.datamarcacao
Of course, I kept the "max" only as an example, because the only correct fields are the first and last (I used min and max). How would you make the 2 and 3 column data popular? Any tips? Thank you.
Solved Rovann, thank you.
– Régis Neis