美文网首页
leetcode数据库部分刷题

leetcode数据库部分刷题

作者: 小T数据站 | 来源:发表于2019-03-01 11:20 被阅读0次

刷题地址

  1. 组合两个表
select person.firstname,person.lastname, address.city, address.state
from person left join address 
on person.personid=address.personid;

2.第二薪水

select 
ifnull((select distinct(salary) 
from employee
order by salary desc
limit 1,1),null) as secondhighestsalary;

3、超过经理收入的员工

select e1.name as employee 
from employee as e1 ,employee as e2 
where e1.managerid=e2.id
and e1.salary>e2.salary;

4、查找重复邮箱

select email
from person
group by email
having count(email) > 1;

5、从不订购的用户

select c.name as customers
from customers c
where c.id not in (select o.customerid from orders o);

6、部门最高工资的员工

select d.name as department, e.name as employee, e.salary 
from department d inner join employee e 
on d.id = e.departmentid 
and e.salary >= (select max(salary) from employee where departmentid = d.id);

7、删除重复的电子邮件

delete p1 
from person p1,person p2
where p1.email = p2.email 
and p1.id > p2.id;

8、上升的温度

select weather.id as id
from weather join weather w 
on datediff(weather.recorddate, w.recorddate) = 1
and weather.temperature > w.temperature;

9、大的国家

select name,population,area
from world
where area>3000000
or population>25000000;

10、超过5名学生的课

select class
from courses
group by class
having count(distinct(student)) >=5

11、换座位

select * from(
    select id-1 as id,student from seat where id%2=0
    union
    select id+1 as id,student from seat where id%2=1 and (id+1) <= (select count(*) from seat)
    union
    select id as id,student from seat where id%2=1 and (id+1) > (select count(*) from seat)
) as t1
order by id asc

12、交换工资

UPDATE salary
SET
    sex = CASE sex
        WHEN 'm' THEN 'f'
        ELSE 'm'
    END;

13、分数排名

select score, (select count(distinct score) from scores where score >= s.score) as rank 
from scores s 
order by score desc 

相关文章

  • leetcode数据库部分刷题

    刷题地址 组合两个表 2.第二薪水 3、超过经理收入的员工 4、查找重复邮箱 5、从不订购的用户 6、部门最高工资...

  • 程序猿刷题网站你知道吗?

    Coderbyte 刷题网LeetCode 刷题网Stack Overflow 刷题网

  • LeetCode刷题

    LeetCode刷题

  • 【刷题】LeetCode部分题型技巧

    前言 这是用来记录在刷LeetCode时遇到的一些问题的技巧,因只记录一些技巧或优化方案故不一定全部记录,自认为的...

  • LeetCode

    LeetCode 刷题随手记 - 第一部分 前 256 题(非会员),仅算法题,的吐槽 https://leetc...

  • Leetcode刷题日记(三)

    刷题的第三周了,这周每天3题。 最近看知乎上说:Leetcode刷100题基本可以应对国内大部分面试。那就先以10...

  • 每日一题之二叉树的深度

    Leetcode 第104题 好久没有刷题了,晋升挂了考虑换个工作了,开始刷题之路。 leetcode国内题库链接...

  • vs code上leetcode插件中测试用例编写

    leetcode插件 为了方便刷题,有很多好用的插件,像官方的leetcode插件,labuladong出的刷题三...

  • leetcode2

    按难度排序,每天刷点leetcode题,抄点解法,大部分解答是在leetcode的dicuss中找到的,没有一一引...

  • leetcode1

    按难度排序,每天刷点leetcode题,抄点解法,大部分解答是在leetcode的dicuss中找到的,没有一一引...

网友评论

      本文标题:leetcode数据库部分刷题

      本文链接:https://www.haomeiwen.com/subject/ehbeyqtx.html