High sal from table

  • Hi friedns

    1. HOw to find out 2nd highest salary from a table can plz tel me?

    2. In my table 10 employees i want 9 th employee sal

    3. how to find out least to 2nd sal from emp table can u any body plz explain me:)

  • you use a technique using the TOP statement twice:

    declare @payroll TABLE (

    salary money,

    firstname varchar(30) )

    INSERT INTO @payroll(salary,firstname)

    SELECT 400.01,'Bob' UNION

    SELECT 800.02,'Bill' UNION

    SELECT 1200.03,'Todd' UNION

    SELECT 100.01,'Nick'

    SELECT TOP 1 X.salary,X.firstname  FROM (

    SELECT TOP 2 salary,firstname FROM @payroll ORDER BY salary DESC

    ) X ORDER BY salary ASC

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Sounds a whole lot like interview or homework questions... would have loved to see the reply... "What have YOU tried?" 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Sounds a whole lot like interview or homework questions... would have loved to see the reply... "What have YOU tried?"

    --Jeff Moden

    Edited: Yesterday @ 9:16 AM by Jeff Moden

    Sounds like you've nailed it Jeff... The original poster should do a spelling/grammar check prior to submission.

     

    Regards,

    Wameng Vang

    MCTS

  • Anyone else up for a quick exam question... I'm sure I can dig out a few of them from these forums ;).

Viewing 5 posts - 1 through 4 (of 4 total)

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