Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 12: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

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