当前位置:   article > 正文

sql力扣_力扣sql

力扣sql

简单

595.大的国家

  1. select
  2. name,
  3. population,
  4. area
  5. from
  6. World
  7. where
  8. (area > 3000000 or population>25000000)

596.超过5名学生的课

  1. select
  2. class
  3. from
  4. course
  5. group by
  6. class
  7. having
  8. count(distinct student) >= 5

196.删除重复的邮箱

  1. delete p1
  2. from
  3. Person p1,
  4. Person p2
  5. where
  6. p1.Email = p2.Email
  7. and
  8. p1.Id > p2.Id

181.超过经理收入的员工

  1. select
  2. e1.Name as Employee
  3. from
  4. Employee e1
  5. inner join
  6. Employee e2
  7. on
  8. e1.MangerId = e2.Id
  9. and
  10. e1.Salary > e2.Salary

620.有趣的电影

  1. select
  2. id,movie,description,rating
  3. from
  4. cinema
  5. where
  6. mod(id,2)=1
  7. and
  8. description <> 'boring'
  9. order by rating desc

  1. select
  2. id,movie,description,rating
  3. from
  4. cinema
  5. where
  6. mod(id,2)=1
  7. and
  8. description <> 'boring'
  9. order by rating desc

197.上升的温度

  1. select w2.Id
  2. from
  3. Weather w1
  4. join
  5. Weather w2
  6. on date_add(w1.RecordDate,INTERVAL 1 day) = w2.RecordDate
  7. and w1.Temperature < w2.Temperature

176.第二高的薪水

  1. select
  2. MAX(e.Salary) as SecondHighestSalary
  3. from
  4. Employee e
  5. where
  6. e.Salary <
  7. (select max(e1.Salary)
  8. from
  9. Employee e1
  10. )

627.交换工资

update salary set sex=case when sex='f' then 'm' else 'f' end;

中等

180.连续出现的数字

  1. select distinct l.Num as ConsecutiveNums from Logs l,Logs l1,Logs l2
  2. where l.Id = l1.Id -1
  3. and l.Id = l2.Id - 2
  4. and l.Num = l1.Num
  5. and l.Num = l2.Num

184.部门工资最高的员工

  1. select
  2. d.Name as Department,
  3. e.Name as Employee,
  4. e.Salary
  5. from
  6. Employee e
  7. inner join
  8. Department d
  9. on
  10. e.DepartmentId = d.Id
  11. where
  12. e.Salary >= (select max(Salary) from Employee e1 where e1.DepartmentId = e.DepartmentId group by DepartmentId)

626.换座位

  1. SELECT (CASE
  2. WHEN MOD(id,2) = 1 AND id = (SELECT COUNT(*) FROM seat) THEN id
  3. WHEN MOD(id,2) = 1 THEN id+1
  4. ElSE id-1
  5. END) AS id, student
  6. FROM seat
  7. ORDER BY id;

177.第N高薪水

  1. CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
  2. BEGIN
  3. RETURN (
  4. # Write your MySQL query statement below.
  5. select distinct Salary from Employee e where N = (select count(distinct Salary) from Employee where Salary >= e.Salary )
  6. );
  7. END

178.分数排名

  1. SELECT
  2. Score,
  3. (SELECT count(DISTINCT score) FROM Scores WHERE score >= s.score) AS Rank
  4. FROM
  5. Scores s
  6. ORDER BY
  7. Score DESC ;

困难

185.部门工资前三高

  1. select
  2. d.name as Department ,
  3. e.name as Employee,
  4. e.Salary as Salary
  5. from
  6. Employee as e
  7. inner join
  8. Department as d
  9. on
  10. e.DepartmentId = d.Id
  11. where
  12. (
  13. select
  14. count(distinct salary)
  15. from
  16. Employee e1
  17. where
  18. e1.Salary> e.Salary
  19. and
  20. e1.DepartmentId = e.DepartmentId
  21. )<3
  22. order by e.DepartmentId,e.Salary desc

601.体育馆的人流量

  1. select distinct a.* from stadium a,stadium b,stadium c
  2. where a.people>=100 and b.people>=100 and c.people>=100
  3. and (
  4. (a.id = b.id-1 and b.id = c.id -1) or
  5. (a.id = b.id-1 and a.id = c.id +1) or
  6. (a.id = b.id+1 and b.id = c.id +1)
  7. ) order by a.id
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/872065
推荐阅读
相关标签
  

闽ICP备14008679号