SQL Language (MOSC)

MOSC Banner

How to solve this sql problem with an analytic function.

edited Nov 13, 2018 12:38PM in SQL Language (MOSC) 5 commentsAnswered ✓

I have the following data

DATE                          PRIMARY SECONDARY

2018-10-22 18:51:10      1           2

2018-10-23 18:51:10      1           2

2018-10-24 18:51:10      1           2

2018-10-25 18:51:10      2           1

2018-10-26 18:51:10      2           1

2018-10-27 18:51:10      2           1

2018-10-28 18:51:10      2           1

2018-10-29 18:51:10      1           2

2018-10-30 18:51:10      1           2

2018-10-31 18:51:10      1           2

2018-11-01 18:51:10      1           2

2018-11-02 18:51:10      2           1

2018-11-03 18:51:10      1           2

2018-11-04 18:51:10      1           2

2018-11-05 18:51:10      1           2

2018-11-06 18:51:10      1           2

Basically it is a date with a host id that was the primary at that time and who the secondary was.   I am trying to write a sql statement that will provide the following output.

StartEndPrimarySecondary
2018-10-22 18:51:102018-10-25 18:51:1012
2018-10-25 18:51:102018-10-29 18:51:1021
2018-10-29 18:51:102018-11-02 18:51:1012
2018-11-02 18:51:102018-11-03 18:51:1021
2018-11-03 18:51:10NULL12

I cannot figure out how to group the rows together!

Tagged:

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center