LeetCode-SQL-easy
LeetCode-SQL-easy
happy life 2022
这个作者很懒,什么都没留下…
展开
-
LeetCode-SQL-1179. 重新格式化部门表
题目链接select id, sum(case month when 'Jan' then revenue end) as Jan_Revenue, #'Jan',"Jan"都可以 sum(case month when 'Feb' then revenue end) as Feb_Revenue, sum(case month when 'Mar' then revenue end) as Mar_Revenue, sum(case month when 'Apr' th原创 2021-04-30 17:27:17 · 79 阅读 · 1 评论 -
LeetCode-SQL-627. 变更性别-easy
题目链接update salaryset sex=( case sex when 'm' then 'f' else 'm' end #无分号);原创 2021-04-30 17:25:32 · 92 阅读 · 1 评论 -
LeetCode-SQL-620. 有趣的电影-easy
题目链接法一:select *from cinemawhere description!="boring" and id%2!=0order by rating desc;法二:select *from cinemawhere description<>"boring" and mod(id,2)=1order by rating desc;原创 2021-04-30 17:23:35 · 78 阅读 · 1 评论 -
LeetCode-SQL-596. 超过5名学生的课-easy
题目链接#可能存在重复的学生记录 所以应对学生字段去重复select classfrom coursesgroup by classhaving count(distinct student)>=5; #count(distinct *)语法不对原创 2021-04-30 17:21:01 · 64 阅读 · 1 评论 -
LeetCode-SQL-595. 大的国家-easy
题目链接select name,population,areafrom Worldwhere area>3000000 or population>25000000;原创 2021-04-30 17:19:01 · 44 阅读 · 1 评论 -
LeetCode-SQL-197. 上升的温度-easy
题目链接法一:select a.id as Idfrom Weather a,Weather bwhere DATEDIFF(a.recordDate,b.recordDate)=1 and a.Temperature>b.Temperature;#MySQL 使用 DATEDIFF 来返回两个日期间的差值法二:select a.id as Idfrom Weather a join Weather b on DATEDIFF(a.recordDate,b.recordDate原创 2021-04-30 17:16:56 · 103 阅读 · 1 评论 -
LeetCode-SQL-196. 删除重复的电子邮箱-easy
题目链接delete p1 //DELETE p1就表示从p1表中删除满足WHERE条件的记录。from Person p1,Person p2where p1.Email=p2.Email and p1.Id>p2.Id;原创 2021-04-30 17:13:16 · 96 阅读 · 1 评论 -
LeetCode-SQL-183. 从不订购的客户-easy
题目链接select Name Customers from Customerswhere Id not in(select CustomerId from Orders);原创 2021-04-30 17:10:32 · 62 阅读 · 1 评论 -
LeetCode-SQL-182. 查找重复的电子邮箱-easy
法一:select distinct a.Emailfrom Person a,Person bwhere a.Id!=b.Id and a.Email=b.Email;法二:select Emailfrom Person group by Emailhaving count(Email)>1;原创 2021-04-22 22:52:36 · 170 阅读 · 0 评论 -
LeetCode-SQL-181. 超过经理收入的员工-easy
select e1.Name Employee from Employee e1,Employee e2where e1.ManagerId=e2.Id and e1.Salary>e2.Salary;原创 2021-04-22 22:50:26 · 82 阅读 · 0 评论 -
LeetCode-SQL-176. 第二高的薪水-easy
法一:select max(Salary) SecondHighestSalaryfrom Employeewhere Salary<(select max(Salary) from Employee);法二:select max(Salary) SecondHighestSalaryfrom Employeewhere Salary not in(select max(Salary) from Employee); #注意加括号原创 2021-04-22 22:48:52 · 72 阅读 · 0 评论 -
LeetCode-SQL-175. 组合两个表-easy
select FirstName,LastName,City,statefrom Person left outer join Address on Person.PersonId=Address.PersonId;原创 2021-04-22 22:43:54 · 75 阅读 · 0 评论