CongliYin的博客

达则兼济天下,穷则独善其身。

Leetcode#184.部门工资最高的员工

select Department.Name as Department, Employee.Name as Employee, Salary from Employee, Department where Department.Id = Employee.DepartmentId and E...

2018-07-11 22:05:34

阅读数:96

评论数:0

Leetcode#197. Rising Temperature

select w1.Id from Weather w1, Weather w2 where w1.Temperature > w2.Temperature and TO_DAYS(w1.Date) = TO_DAYS(w2.Date) + 1 select w1...

2018-03-28 18:25:34

阅读数:26

评论数:0

Leetcode#196. Delete Duplicate Emails

delete p2 from Person p1, Person p2 where p1.Id < p2.Id and p1.Email = p2.Email

2018-03-28 18:17:16

阅读数:48

评论数:0

Leetcode#183. Customers Who Never Order

题目描述:查找没有预定(orders)的顾客(customers) 普通方法: select Name as Customers from Customers c where c.Id not in (select CustomerId from Orders) 使用左连接: sele...

2018-03-23 19:54:10

阅读数:16

评论数:0

Leetcode#182. Duplicate Emails

题目描述:查找下表中Email重复的Email 使用group by: select Email from Person group by Email having count(*) > 1 普通方法: select distinct p1.Email from ...

2018-03-23 19:39:24

阅读数:23

评论数:0

Leetcode#181. Employees Earning More Than Their Managers

题目描述:给定以下表,Id为唯一标识,ManagerId为其管理者,查找Employee的Salary多于Manager的Employee的Name,如下: SQL语句如下: (1)使用普通select…from…语句 select e1.Name as Employee from ...

2018-03-21 15:04:51

阅读数:30

评论数:1

Leetcode#180. Consecutive Numbers

题目描述:选择下表中连续出现三次的Num作为ConsecutiveNums,Logs表格如下图: 结果: SQL语句: select distinct l1.Num as ConsecutiveNums from Logs l1, Logs l2, Logs l3 where l1....

2018-03-21 11:15:32

阅读数:71

评论数:0

Leetcode#178. Rank Scores

解题思路:计算大于等于自己的个数有多少作为自己的rank select Score,(select count(*) from (select distinct Score S from Scores) as tmp where S ...

2018-03-17 17:07:25

阅读数:76

评论数:0

Leetcode#177. Nth Highest Salary

题目描述:写一个SQL查询,得到第n个最高的薪水值,如当 n=2 时,结果如下: SQL语句如下,注意分号;的位置: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN Declare M INT; /*声...

2018-03-16 11:36:23

阅读数:70

评论数:1

Leetcode#176. Second Highest Salary

题目描述:实现一个SQL查询选出第二高的薪水,输入输出要求如下图: salary表: 查询结果表: 解题思路:一个很简单的思路是,第二高的薪水就是除去第一高薪水之后,最高的那个薪水,所以将最高薪水 x 的选出来,小于 x 的最大值便是第二高了。注意:查询结果表的列名为:SecondH...

2018-03-16 11:19:15

阅读数:21

评论数:0

Leetcode#175. Combine Two Tables

题目描述:有如下两个表Table和Address,请选择FirstName, LastName, City, State这几个属性出来,不管Address中的属性是否存在; 解题思路:这是一道简单的SQL语句题目,选出两个表中的FirstName, LastName, City, State...

2018-03-16 11:10:28

阅读数:68

评论数:0

提示
确定要删除当前文章?
取消 删除
关闭
关闭