How well do you know MAX?

  • Glad I had finished my first cup of morning coffee to wake up that part of my mind that thinks logically.

    Thanks, a nice way to end the week, now hoping the remainder of my day is as good.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Not so much about MAX as it is about logic. Nice question. Thanks.

  • Nice question, I almost fell for answering third highest.

  • Good question, nice little brain teaser for a friday morning.

  • I enjoyed this question. Thanks!

  • Thanks for the question. Glad it combined T-SQL with some logic. Not all questions have to have something to do with unexpected behavior/"features" of SQL Server. Once you know those things, you still have to apply that information logically to solve a problem. Important to know if the problem you solve is the problem you meant to solve.

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • That was an excellent question, and not at all a "trick question"... very nice!

    ron

    -----
    a haiku...

    NULL is not zero
    NULL is not an empty string
    NULL is the unknown

  • Got me tricked. Nice question. Thanks!

  • Best question for ages!

    Nice one VM!

  • This may be a trick question, but it is a GOOD trick question. This is actually the sort of thing that happens in the real world with inexperienced developers, or when people have gone without sleep for too long and are still working. Good to train that sort of thinking.

  • For those who were expecting the third highest salary, here is a select for that

    declare @table table(ID int identity(1,1) not null, Name varchar(10), Salary float)

    insert into @table values ('A',123.45)

    insert into @table values ('B',543.44)

    insert into @table values ('C',654.44)

    insert into @table values ('D',848.93)

    insert into @table values ('C',2372.46)

    insert into @table values ('D',4775.44)

    insert into @table values ('E',5676.45)

    insert into @table values ('F',244.44)

    insert into @table values ('G',3434.44)

    insert into @table values ('H',666.93)

    insert into @table values ('I',444.46)

    insert into @table values ('J',123.44)

    select max(Salary) from @table where Salary not in

    (

    select max(Salary) from @table where Salary not in

    (

    select max(Salary) from @table

    )

    )

    -- This returns the third highest salary

    Select MAX(t2.Salary) As "Salary"

    From (Select Salary From @table Where Salary Not In (Select MAX(Salary) From @table)) As "t2"

    Where t2.Salary Not In

    (

    -- This returns the second highest salary

    Select MAX(t1.Salary) As "Salary"

    From (Select Salary From @table

    Where Salary Not In

    (

    -- This returns the highest salary

    Select MAX(Salary) From @table

    )) As "t1"

    );

    Enjoy!

    Dave

  • Am I the only person who thinks those salaries are horrifically low?! If I was only paid 5000 units of currency per year (regardless of currency!) I wouldn't be best pleased!

    😀

    again, nice question.

    Ben

    ^ Thats me!

    ----------------------------------------
    01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
    ----------------------------------------

  • BenWard (8/5/2011)


    Am I the only person who thinks those salaries are horrifically low?! If I was only paid 5000 units of currency per year (regardless of currency!) I wouldn't be best pleased!

    😀

    again, nice question.

    I just assumed those were hourly, much like mine. 😛

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (8/5/2011)


    BenWard (8/5/2011)


    Am I the only person who thinks those salaries are horrifically low?! If I was only paid 5000 units of currency per year (regardless of currency!) I wouldn't be best pleased!

    😀

    again, nice question.

    I just assumed those were hourly, much like mine. 😛

    lots of rupees for you! 😀

    Ben

    ^ Thats me!

    ----------------------------------------
    01010111011010000110000101110100 01100001 0110001101101111011011010111000001101100011001010111010001100101 01110100011010010110110101100101 011101110110000101110011011101000110010101110010
    ----------------------------------------

  • Sean Lange (8/5/2011)


    BenWard (8/5/2011)


    Am I the only person who thinks those salaries are horrifically low?! If I was only paid 5000 units of currency per year (regardless of currency!) I wouldn't be best pleased!

    😀

    again, nice question.

    I just assumed those were hourly, much like mine. 😛

    Or match appearance fees!

    Thanks for the question btw...

Viewing 15 posts - 16 through 30 (of 59 total)

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