find max

  • raghuldrag (8/17/2012)


    friends ,

    select top 2*

    from empy order by cast(sal as int)desc

    in these query has given first two max values, now i need the ouput while i am giving the position =3 means third max sal has to display.....i.e 2500

    Properly asked question contains over 50% of answer.

    The way you present yours one, makes very hard to understand exactly what do you want.

    If you want single 3rd largest record from your datasetup on SQL2000 you can do:

    select top 1 *

    from (

    select top 3 *

    from #emp

    order by cast(sal as int)

    desc

    ) a

    order by cast(sal as int)

    I would suggest you to read the article under the link at the bottom of my signature. If you follow its tips, you would get appropriate answer to your question in a first reply...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • raghuldrag (8/17/2012)


    ya its workin..... suppose i need the particular top 3rd postion of max salary means how to modify

    Declare @position Varchar(30)

    Set @position = 'sales'

    Select Top 1 * From

    (

    Select top 3 * From Ex Where Job = @position

    Order By sal DESC

    ) As a

    Order By sal DESC

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply