0
I have an appointment Oracle SQL that returns the records per row, and I wanted to turn that into column. I did a search and find that the Pivot does this, but I don’t know how to use it, someone can 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 the date of the movement and the marking times as column, as example below.
Dt. Mov. | Dt1 | Dt 2 | Dt 3 | Dt 4<br>
23/08/2017 | 800 | 1206 | 1311 | 1802
What’s the need for that? If this is just one way to view the returns from a look here https://answall.com/questions/225916/return
– R.Santos
@R.Santos I need each record of 'Time' in a column, in the form of string_agg (oracle), it brings all the records and one column only. Thank you.
– Tiago Martins
Does it have any field indicating that the type of input/output , or is just the position , the position being an artificial sequence could be created by "Analytic functions" .
– Motta
@Motta has yes! There is a column with the information 'E (input)' and’S (output)'.
– Tiago Martins
Still complicates because they are two tags for fourth markings , apart from the markings of the staff who turns the night , vigias , callcenters etc, already used Analytic functions ?
– Motta
@Motta In addition to the 'E' and’S' column I have another column with the information '1' and '2' to indicate the first and second rounds. As for the night-time appointments and so on, it doesn’t exist on my set.
– Tiago Martins
Pivot sql seems to be simple so , tomorrow , if you have time , I put something.
– Motta
@Motta ok, I stand by. I thank you in advance.
– Tiago Martins
Let’s go continue this discussion in chat.
– Tiago Martins