Advertisement

05.10.2008 at 12:24PM PDT, ID: 23391978
[x]
Attachment Details

sql result using partition by functions

Asked by vkchaitu82 in Oracle Database

Tags: sql

Hi experts,

I have  table1 in which data is like this.Here entity_id and eff_dt forms the primary key.
Table1                         
entity_id      entity_n       eff_dt      end_dt
2000      ABC      1/1/2001      1/1/2002
2000      ABC      1/1/2002      1/1/2003
2000      DEF      1/1/2003      1/1/2004
2000      ABC      1/1/2004      
2001      KLM      1/1/2006      1/1/2007
2001      KLM      1/1/2007      1/1/2008
2001      KLM      1/1/2008      
2002      OPQ      1/1/2001      
2003      PQR      1/1/1950      1/1/1951
2003      RST      1/1/1951      
2004      MNO      1/1/1960      1/1/1961
2004      PQR      1/1/1961      1/1/1962
2004      MNO      1/1/1962      1/1/1963
2004      PQR      1/1/1963      

I need the output like this.
Result                  
entity_id      entity_n       eff_dt      end_dt
2000      ABC      1/1/2001      1/1/2003
2000      DEF      1/1/2003      1/1/2004
2000      ABC      1/1/2004      
2001      KLM      1/1/2006      
2002      OPQ      1/1/2001      
2003      PQR      1/1/1950      1/1/1951
2003      RST      1/1/1951      
2004      MNO      1/1/1960      1/1/1961
2004      PQR      1/1/1961      1/1/1962
2004      MNO      1/1/1962      1/1/1963
2004      PQR      1/1/1963      

I tried to use Partition by functions to get the output  but some or the other case is failing.
The logic behind the result is as follows
entity_id      entity_n       eff_dt      end_dt
2000      ABC      1/1/2001      1/1/2002
2000      ABC      1/1/2002      1/1/2003
2000      DEF      1/1/2003      1/1/2004
2000      ABC      1/1/2004      

For entity_id 2000 entity_n starts on 1/1/2001(eff_dt) and continues till 1/1/2003.The first two records are same.The eff_dt should be taken from first record and end_dt from second record.Again entity_n DEF starts from 1/1/2003 and ends on 1/1/2004. ABC starts again on 1/1/2004 and never ends.
So my out put should result in
entity_id      entity_n       eff_dt      end_dt
2000      ABC      1/1/2001      1/1/2003
2000      DEF      1/1/2003      1/1/2004
2000      ABC      1/1/2004      

I am attching this excel which has the sample data easy to load.
Thanks in advance.

Start Free Trial
Attachments:
 
Sample data to load
 
[+][-]05.10.2008 at 05:11PM PDT, ID: 21540999

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 05:37PM PDT, ID: 21541075

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 05:53PM PDT, ID: 21541135

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 06:05PM PDT, ID: 21541154

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 06:38PM PDT, ID: 21541197

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.10.2008 at 06:58PM PDT, ID: 21541233

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 08:32AM PDT, ID: 21542675

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 08:36AM PDT, ID: 21542694

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 04:50PM PDT, ID: 21543966

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 10:00PM PDT, ID: 21544743

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2008 at 10:08PM PDT, ID: 21544755

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 02:55AM PDT, ID: 21545590

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 05:37AM PDT, ID: 21546294

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 07:20AM PDT, ID: 21547214

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2008 at 07:23AM PDT, ID: 21547235

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Oracle Database
Tags: sql
Sign Up Now!
Solution Provided By: sdstuber
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628