前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LeetCode SQL

LeetCode SQL

作者头像
hankleo
发布2020-09-17 10:41:59
2900
发布2020-09-17 10:41:59
举报
文章被收录于专栏:Hank’s Blog

175.【简单】组合两个表

代码语言:javascript
复制
select p.FirstName,p.LastName,a.City,a.State from person p left join address a on p.personid=a.personid;

176.【简单】第二高的薪水

代码语言:javascript
复制
select ifnull((select distinct(Salary) from Employee order by Salary desc limit 1,1),null) as SecondHighestSalary;

177.【中等】第N高的薪水

代码语言:javascript
复制
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
set n=n-1;
  RETURN (
      # Write your MySQL query statement below.
      select distinct Salary as getNthHighestSalary
      from Employee
      order by Salary DESC
      limit N,1
  );
END

181.【简单】超过经理收入的员工

代码语言:javascript
复制
select e1.Name as Employee from Employee as e1,Employee as e2
where e1.Salary > e2.Salary and e1.ManagerId = e2.Id;

182.【简单】查找重复的电子邮箱

代码语言:javascript
复制
select Email from Person
group by Email having count(Email)>1;

183.【简单】从不订购的客户

代码语言:javascript
复制
select c.Name as Customers from Customers c
left join Orders o on c.Id=o.CustomerId
where o.Id is null;

196.【简单】删除重复的电子邮箱

代码语言:javascript
复制
delete p1 from Person p1,Person p2
where p1.Email=p2.Email
and p1.Id > p2.Id;

197.【简单】上升的温度

代码语言:javascript
复制
select w1.Id from Weather w1,Weather w2
where DATEDIFF(w1.RecordDate,w2.RecordDate)=1
and w2.Temperature<w1.Temperature;

595.【简单】大的国家

代码语言:javascript
复制
select name,population,area from World
where area>3000000 or population>25000000;

596.【简单】超过5名学生的课

代码语言:javascript
复制
select class from courses
group by class
having count(distinct student)>=5;

620.【简单】有趣的电影

代码语言:javascript
复制
select * from cinema
where description <> "boring" and id%2=1
order by rating desc;

627.【简单】交换工资

代码语言:javascript
复制
update salary set sex = if(sex="m" ,"f", "m")

1179.【简单】重新格式化部门表

代码语言:javascript
复制
SELECT DISTINCT id AS "id",
SUM(IF (month = "Jan", revenue, null)) AS "Jan_Revenue",
SUM(IF (month = "Feb", revenue, null)) AS "Feb_Revenue",
SUM(IF (month = "Mar", revenue, null)) AS "Mar_Revenue",
SUM(IF (month = "Apr", revenue, null)) AS "Apr_Revenue",
SUM(IF (month = "May", revenue, null)) AS "May_Revenue",
SUM(IF (month = "Jun", revenue, null)) AS "Jun_Revenue",
SUM(IF (month = "Jul", revenue, null)) AS "Jul_Revenue",
SUM(IF (month = "Aug", revenue, null)) AS "Aug_Revenue",
SUM(IF (month = "Sep", revenue, null)) AS "Sep_Revenue",
SUM(IF (month = "Oct", revenue, null)) AS "Oct_Revenue",
SUM(IF (month = "Nov", revenue, null)) AS "Nov_Revenue",
SUM(IF (month = "Dec", revenue, null)) AS "Dec_Revenue" 
FROM Department GROUP BY id
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-07-03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档