0

I have a column A which displays values corresponding to the input Date SYSDATE . I want to bifurcate that column into two parts such that one part displays the data corresponding to SYSDATE and the other part displays data corresponding to SYSDATE-1 i.e. previous day .

Now the issue is that output columns are same for both the parts,its just the change in the processing of the query where one part takes input Date SYSDATE and other takes input SYSDATE-1 .

I am stuck at the implementation of this requirement .

Select A, B,C from Table -- Generalised query , now Column A has to be split into two columns A1 , A2 ,Issue is how to display A1,A2 .

I have no clue of how to proceed .

1
  • Hey Radha, Can you please show what you have tried? the code? Commented Aug 29, 2019 at 6:16

1 Answer 1

1

You could try a self join here:

SELECT
    t1.value,
    t2.value,
    t1.dt,
    t2.dt
FROM yourTable t1
INNER JOIN yourTable t2
    ON t2.dt = t1.dt - 1
WHERE
    t1.dt >= TRUNC(SYSDATE);

This would pair up records from today only to corresponding records at the same time one day earlier.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please explain the last condition : t1.dt >= TRUNC(SYSDATE)
Sure, this is just saying that dt has to occur on or after midnight of the current date. So, my result set would only include records where the first column is from today (and the second column the same points in time, one day earlier).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.