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 command?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-04, 09:33
mrbear mrbear is offline
Registered User
 
Join Date: Mar 2004
Posts: 21
sql command?

i have a table lar, one column got a lot figures. Then i want to get the five of the highest number. how am i going to write the sql statment. the column name is figure1.

i try writing "select * from prod count(figure1 * 0.05) but it wont work
Reply With Quote
  #2 (permalink)  
Old 03-22-04, 10:04
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Select columns
from
(select columns, RANK() OVER (ORDER BY column DESC) RN
from tableA
) V
where V.RN <= 5;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 03-22-04, 10:50
mrbear mrbear is offline
Registered User
 
Join Date: Mar 2004
Posts: 21
r1233456 i dun get wat you mean, wat is that RANK() over and the RN...
Reply With Quote
  #4 (permalink)  
Old 03-22-04, 14:23
saqibmabbasi saqibmabbasi is offline
Registered User
 
Join Date: Mar 2004
Location: Karachi, Pakistan
Posts: 3
Hello mrbear,
What "r123456" is trying to convey is that you should perform the top N analysis. in which what is done is that suppose you want to get the Top five ranked values. the top values can change according to the scenario. suppose you want to get the top 5 hit singles orr movies. Now these rankings are done so that the top five movies will be ranked as
1,2,3,4,5 .... but if you want to get the top 5 highest price of an item then you will first have to sort the output in Descending order and then pick the top five values.
In the query mentioned by "r123456"

Select columns from
(select columns, RANK() OVER (ORDER BY column DESC) RN from tableA ) V
where V.RN <= 5;

The RN is the RowNum, it is a pseudocolumn and acts like a serial number, so what it is doing is that it is first sorting the table into the Descending order and then it is picking up the top 5 rows.

Hope this helps.
Take care
Saqib...
Reply With Quote
  #5 (permalink)  
Old 03-22-04, 21:13
mrbear mrbear is offline
Registered User
 
Join Date: Mar 2004
Posts: 21
THanks, i get wat you mean already. thanks for the help
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