Results 1 to 5 of 5

Thread: sql command?

  1. #1
    Join Date
    Mar 2004
    Posts
    21

    Unanswered: 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

  2. #2
    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.

  3. #3
    Join Date
    Mar 2004
    Posts
    21
    r1233456 i dun get wat you mean, wat is that RANK() over and the RN...

  4. #4
    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...

  5. #5
    Join Date
    Mar 2004
    Posts
    21
    THanks, i get wat you mean already. thanks for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •