LeetCode 数据库模块刷题纪要

解答所选数据库均为MySQL,以下解答并非最佳解答,若有最佳解答,欢迎留言交流~

难度:简单

  • 175.组合两个表
select p.FirstName,p.LastName,a.City,a.State from Person p
left join Address a on
p.PersonId=a.PersonId;
  • 176.第二高的薪水
select IFNULL 
((select distinct Salary from Employee order by Salary DESC Limit 1,1),NULL)
as SecondHighestSalary;
  • 181.超过经理收入的员工
select a.Name as Employee from Employee a,Employee b 
where a.ManagerId=b.Id and a.Salary > b.Salary
  • 182.查找重复的电子邮箱
select Email from Person group by Email having Count(Email) > 1
  • 183.从不订购的客户
select Name as Customers from Customers where Id not in
(select c.Id from Orders o
left join Customers c
on c.Id=o.CustomerId)
  • 196.删除重复的电子邮箱
DELETE from Person WHERE NOT EXISTS (
SELECT c.Id FROM
    (SELECT Min(Id) as Id FROM Person GROUP BY Email)c
     WHERE c.Id=person.Id);
  • 197.上升的温度
SELECT
    weather.Id
FROM
    (
        SELECT
            DATE_ADD(w.RecordDate, INTERVAL 1 DAY) AS RecordDate,
            w.Temperature
        FROM
            weather w
    ) c,
    weather
WHERE
    c.RecordDate = weather.RecordDate
AND c.Temperature < weather.Temperature;
  • 595.大的国家
select name,population,area from World where population > 25000000 or area > 3000000
  • 596.超过5名学生的课
SELECT
    class
FROM
    (
        SELECT DISTINCT
            student,
            class
        FROM
            courses
    ) c
GROUP BY
    c.class
HAVING
    count(c.class) >= 5
  • 620.有趣的电影
select * from cinema where id%2=1 and description <> "boring" order by rating desc;
  • 627.交换工资
UPDATE salary set sex = CASE WHEN (sex='f') THEN 'm' ELSE 'f' END
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值