力扣数据库的一些题解

Leetcode 175

image
题解思路:
首先想到,要输出的是合并的表的数据,并且由无论person是否有地址信息,都需要基于上述量表提供person的以下信息可知,在将两表连接过程中,要全部返回person的行。

代码如下:

select Person.FirstName,Person.LastName,Address.City,Address.State
from Person LEFT JOIN Address

on  Person.PersonId = Address.PersonId;

Leetcode176

解题思路:这里要注意要把输出的表格的列名换掉,还有这里要单独输出排序后的第二行的数据,这里有以下两种输出方法

* limit 2,1  //limit后面是从第2条开始读,读取1条信息,即读取第3条数据
* limit 2 offset 1  //limit后面跟的是2条数据,offset后面是从第1条开始读取,即读取第2,3条

题解如下:

select (select DISTINCT
Employee.Salary 
from Employee
order by Salary DESC
 LIMIT 1,1)AS SecondHighestSalary ;

Leetcode178

原文地址:https://www.cnblogs.com/hello-liu/p/14828780.html