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 > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Analytic function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-04, 11:06
shalufannie shalufannie is offline
Registered User
 
Join Date: Mar 2004
Posts: 2
Question SQL Analytic function

If have following data set:

SQL> select * from t;

WAC WAM PRICE PRODUCT
---------- ---------- ---------- ----------
10 5 100 long
11 4 99 long
14 7 97 long
15 3 101 long
15 9 99 long
21 4 98 long
21 7 102 long
25 8 104 long
12 4 102 long
5 2 100 long
5 8 101 long
5 10 98 long
9 5 102 long

And a sql query:
----------------
Select
count(wac) over (partition by wac order by wac) wac_count1,
wac,
lead(wac, 1) over (order by wac) next_wac
From t;

This qry gives following result:

WAC_COUNT1 WAC NEXT_WAC
---------- ---------- ----------
3 5 5
3 5 5
3 5 9
1 9 10
1 10 11
1 11 12
1 12 14
1 14 15
2 15 15
2 15 21
2 21 21
2 21 25
1 25

I have the count for wac in column wac_count1 in the above query, how can I get another column wac_count2 that has the count on next_wac ?

Any suggestions...!!

Thanks
Shalu
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