zoukankan      html  css  js  c++  java
  • leetcode数据库题目及答案汇总

    1、 第二高的薪水
    select ifnull((select distinct Salary from Employee order by Salary desc limit 1,1),null) as SecondHighestSalary;
     
    2、第N高的薪水
    select distinct Salary from Employee e where N = (select count(distinct Salary) from Employee where Salary >= e.Salary );
     
    3、分数排名
      select Score,(select count(distinct score) from Scores where score >= s.score) as Rank from Scores as s order by Score desc;
     
    4、超过经理收入的员工
      select e1.Name as Employee from Employee as e1,Employee as e2 where e1.ManagerId=e2.Id and e1.Salary>e2.Salary;
     
    5、 查找重复的电子邮箱
    select Email from Person group by Email having count(Email)>1;
     
    6、从不订购的客户
    select c.Name as Customers from Customers as c left join Orders as o on c.Id = o.CustomerId where c.Id not in (select c.Id from Customers as c,Orders as o where c.Id = o.CustomerId);
     
    7、部门工资最高的员工
        select d.Name as Department,e.Name as Employee,e.Salary from Department as d inner join Employee as e on d.Id = e.DepartmentId and e.Salary>=(select max(Salary) from Employee where DepartmentId=d.Id);
     
    8、删除重复的电子邮箱
       delete p1.* from Person p1,Person p2 where p1.Email=p2.Email and p1.id>p2.id;
     
    9、上升的温度
      select w1.Id from Weather w1 join Weather w2 on DATEDIFF(w1.RecordDate, w2.RecordDate) = 1 where w1.Temperature>w2.Temperature;
     
    10、交换性别
    update salary set
    sex = case sex
    when 'm' then 'f'
    else 'm'
    end;

  • 相关阅读:
    第十章 系统级I/O
    第九章 虚拟内存
    第六章 存储器层次结构
    第八章 异常控制流(下)
    第八章 异常控制流(上)
    第三章 机器的程序级表示(下)
    第三章 机器的程序级表示(中)
    第三章 机器的程序级表示(上)
    python学习之列表的定义以及增删改查
    Python学习之字符串中的下标和切片以及逆序
  • 原文地址:https://www.cnblogs.com/chaofan-/p/10412273.html
Copyright © 2011-2022 走看看