I have an Oracle SQL query that returns records per line, and I wanted to turn this into column. I've researched and found that Pivot does this, but I'm not sure how to use it, can anyone help me?
CURRENT RETURN:
SELECT
AFD.CODEMP AS CODEMP,
AFD.CODFUNC AS CODFUNC,
AFD.DTMOV,
AFD.HORA AS HORA,
OCO.DESCROCOR,
AFD.FECHADO
FROM
TFPAFDT AFD
LEFT JOIN TFPOCO OCO ON OCO.NUOCOR = AFD.NUOCOR
WHERE
AFD.CODEMP = 1
AND AFD.CODFUNC = 702
AND (
( AFD.DTMOV BETWEEN TO_DATE ( '01/08/2017', 'DD-MM-YYYY' ) AND TO_DATE ( '30/08/2017', 'DD-MM-YYYY' ) )
OR ( AFD.DTINIJORNADA BETWEEN TO_DATE ( '01/08/2017', 'DD-MM-YYYY' ) AND TO_DATE ( '30/08/2017', 'DD-MM-YYYY' ) )
)
EXPECTED RETURN:
I would like the return lines to come from the date of the move and the marking hours as a column, as shown below.
Dt. Mov. | Dt1 | Dt 2 | Dt 3 | Dt 4<br>
23/08/2017 | 800 | 1206 | 1311 | 1802