Home » SQL & PL/SQL » SQL & PL/SQL » Oracle analytic query help (Oracle 10g R10.0.2)
Oracle analytic query help [message #641114] Mon, 10 August 2015 13:15 Go to next message
parmarjm
Messages: 25
Registered: October 2006
Junior Member
I am using Oracle 10g Release 10.0.2

Here is the situation:

I have record in my table looks like this :

Cust_id beg_dt end_dt sg_cd

264321502 01-MAY-97 19-MAR-98 1

264321502 21-MAY-98 15-OCT-98 6

264321502 20-OCT-98 22-APR-99 6

264321502 23-APR-99 25-APR-00 6

264321502 27-APR-00 20-JAN-02 6

264321502 25-JAN-02 15-MAY-02 6

264321502 21-MAY-02 27-MAY-02 6

264321502 31-MAY-02 17-FEB-03 6

264321502 21-FEB-03 06-SEP-04 1

264321502 25-FEB-03 25-FEB-03 1

264321502 31-MAR-03 30-APR-03 1

264321502 07-SEP-04 26-DEC-04 6

264321502 29-DEC-04 03-JAN-06 6

264321502 04-JAN-06 03-JAN-07 12

264321502 04-JAN-06 03-JAN-07 12

264321502 04-JAN-06 03-JAN-07 12



I need query output like

Cust_id beg_dt end_dt sg_cd

264321502 01-MAY-97 19-MAR-98 1

264321502 21-MAY-98 17-FEB-03 6

264321502 21-FEB-03 30-APR-03 1

264321502 07-SEP-04 03-JAN-06 6

264321502 04-JAN-06 03-JAN-07 12



basically, I need to pick min(beg_dt) max(end_dt) by sg_cd for this cust id.



Any help is very very appreciated:

My query is like this



select cust_id, beg_dt, end_dt, sg_cd,

min(beg_dt) over (partition by cust_id, sg_Cd) as new_beg_dt,

max(end_dt) over (partition by cust_id, sg_cd) as end_Dt_nw

from cust_tab;
Re: Oracle analytic query help [message #641115 is a reply to message #641114] Mon, 10 August 2015 13:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read
Re: Oracle analytic query help [message #641116 is a reply to message #641114] Mon, 10 August 2015 13:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I need to pick min(beg_dt) max(end_dt) by sg_cd for this cust id.


You don't need any analytic function for this; you need aggregate functions.

If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data.
Before, Please read How to use [code] tags and make your code easier to read.

[Updated on: Mon, 10 August 2015 14:02]

Report message to a moderator

Re: Oracle analytic query help [message #641119 is a reply to message #641114] Mon, 10 August 2015 13:56 Go to previous message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
And STILL you refuse to do us the courtesy of following the posting guidelines as you have been asked many times before
Previous Topic: Need PL/SQL Script
Next Topic: union
Goto Forum:
  


Current Time: Thu Apr 25 03:57:38 CDT 2024