I need to make an appointment by bringing the second value of a field to the first row. That is, I need the value of the first field in the "Time1" column to be filled with the value of the second field in the "Time" column. I created an empty field which is the field "Time1" to make a case pulling values but I am not able to do the pull value as I want.
Can anyone help me?
Query:
SELECT linhas,
ctns,
usuario,
hora,
dia,
tempo,
CASE
WHEN tempo1 IS NULL THEN tempo
ELSE tempo
END AS tempo1
FROM
(SELECT rownum AS linhas,
a.ctn AS ctns,
a.usu AS usuario,
a.hh AS hora,
a.dia1 AS dia,
a.dia2 AS tempo,
' ' AS tempo1
FROM
(SELECT Distinct(DLYTRN.To_subnum) AS ctn,
DLYTRN.usr_id AS usu,
To_Char (DLYTRN.trndte, 'HH24') AS HH,
To_Char (DLYTRN.trndte, 'DD') AS dia1,
To_Char (DLYTRN.ins_dt, 'HH24:MI:SS') AS dia2
FROM DLYTRN
WHERE DLYTRN.trndte >= trunc (sysdate,'MM') -60
AND DLYTRN.oprcod = 'UPK'
AND DLYTRN.actcod IN ('CASPCK',
'PLAPCK',
'OTRPCK')
AND DLYTRN.usr_id = 'SCRUZ'
ORDER BY To_Char (DLYTRN.ins_dt, 'HH24:MI:SS'),
DLYTRN.usr_id) a)