If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > How to retrieve the max sequence number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jul 2003
Posts: 5
How to retrieve the max sequence number

Hi,
I have the following values in my table

agnum sitenum month year sequence values
100 010 05 2003 1 50
100 020 05 2003 1 50
100 030 05 2003 1 50
100 040 05 2003 1 50
100 050 05 2003 1 50
100 010 05 2003 2 60
100 020 05 2003 2 40
100 030 05 2003 2 40

The out put that i would like is :
agnum month year sum(values)
100 05 2003 240 ( 60+40+40+50+50)


ie: I want the total of all the values for the sites which have the max( sequence) eg: site 010,020,030 have sequence 2 . So i want the total to include only the values of 010,020,030 with sequence 2 and it should include the values of site 040,050 with sequence 1 since site 040,050 donot have a resubmission for the month 05/2003

Any help is much appreciated

Jayanthi
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Required Query

Jayanti
Kindly use the following query to get the answers.

select a.agnum, sum(a.values1) from table1 a, (select max(sequnce) maxseq, sitenum from table1 group by sitenum) tmptable where a.sequnce=tmptable.maxseq and a.sitenum=tmptable.sitenum group by a.agnum;

In order to get the max sequence number for all the sitenum, you would use the following query
select max(sequnce) maxseq, sitenum from table1 group by sitenum;

Thanx and Regards
Aruneesh
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jul 2003
Posts: 5
Re: Required Query

Thank you arun,
That worked for me

Jayanthi


Quote:
Originally posted by aruneeshsalhotr
Jayanti
Kindly use the following query to get the answers.

select a.agnum, sum(a.values1) from table1 a, (select max(sequnce) maxseq, sitenum from table1 group by sitenum) tmptable where a.sequnce=tmptable.maxseq and a.sitenum=tmptable.sitenum group by a.agnum;

In order to get the max sequence number for all the sitenum, you would use the following query
select max(sequnce) maxseq, sitenum from table1 group by sitenum;

Thanx and Regards
Aruneesh
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On