Oracle-SQL
I have a table that records the point records that each employee does. The table gives 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 now need to transpose these columns, bringing these beats as columns (TABLE AS I WANT):
Contrato | Data | Hora 1 | Hora 2 | Hora 3 | Hora 4
But I find it difficult to bring the records, see where I went: (CURRENT QUERY)
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, since the only correct fields are the first and last (I used min and max). How would you use popular 2 and 3 column data? Any tips? Thank you.