×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / have a employee table like this, find the 5th highest salary in it
    have a employee table like this:


    Name Salary
    -------------------------------------------------- -----------
    Bob 23456
    Sam 34567
    Bill 45678
    Green 12345
    Ken 12345
    Welly 59000
    Lion 45678
    • 如果是SQL 2000, Select top 5 * from employee 如果是Oracle,我去查一下先,hehe
    • 不好意思,把上面的查询当成子查询,查最少的那个就可以了
      • oracle
        select name from tablename where rownum = 5 order by salary
        • 如果有两条结果,你的语句能查出来吗?
          • Oracle: select distinct name from tablename where salary = (select sum(salary)/count(*) as x from tablename where rownum = 5 group by x order by x);
          • SQL Server:
            select * from employee where salary= (
            select top 1 salary from employee
            where salary not in (select distinct top 4 salary from employee order by salary )
            order by salary )
            • almost correct
              the answer is


              select * from employee where salary=
              (
              select max(salary) from employee
              where salary not in
              (
              select top 4 salary from employee order by salary desc)
              )
              )
              • Yes. I was too careless and missed "desc" in my statement, which returned the 5th lowest salary instead.:)
          • 思路基本就是这样:先找出5个最高的值,然后取他们中最低的,就是第五高的。之后按这个工资值找出所有的符合的人。应该有多少都查得出来的。
    • 你们公司的人怎么挣这么少?不是说IT的都能挣个十万八万的吗?
      • 看明白了再说话省得别人笑话
        • 压根就没往明白看。但我想说就说,怕什么人家笑话?
          • 无聊者有理
            • 你有理。
      • 不好意思,忘了往后面加个0,哈哈。。。。