RE: more sql

From: Stephens, Chris <chris_stephens_at_admworld.com>
Date: Wed, 12 Mar 2008 13:57:16 -0500
Message-ID: <7070047601C21A4CB387D50AD3661F6E093E9015@050EXCHANGE.research.na.admworld.com>


Ahh. I believe I found the answer to my own question with portioned outer joins.  

chris  

From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Stephens, Chris Sent: Wednesday, March 12, 2008 12:10 PM To: Oracle-L Freelists
Subject: more sql  

I have learned a lot about sql this morning but I can't quite close the gap between what I am reading and what I need to do. I know the following query can be written far more efficiently:  

select pstart.periodID, ps1.projectNumber, ps1.statusID, ps1.changeDate

from vw_project_status_period ps1,

           period pstart,

          period pstop

where pstart.periodid >= ps1.periodid and

              pstop.endDate = ( select max( p.endDate )

                                                                from
vw_project_status_period ps2,  

period p

                                                                 where
ps2.projectnumber = ps1.projectNumber and  

ps2.periodid = p.periodid and p.endDate <= pstart.endDate

  ) and

             pstop.periodid = ps1.periodid;    

vw_project_status_period contains info on when a projects status changes. The above query fills in period gaps between changes for each project. I am having trouble figuring out how to 'fill in the gaps' of periods between the change dates. After that it is just a matter of using last_value.  

I have been looking at this for a few hours and figured I'd throw another sql question to the list.    

CONFIDENTIALITY NOTICE:
This message is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by email reply.

CONFIDENTIALITY NOTICE:
        This message is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by email reply.

--
http://www.freelists.org/webpage/oracle-l
Received on Wed Mar 12 2008 - 13:57:16 CDT

Original text of this message