【Leetcode-数据库】基础操作
@
题目:连接两个表
NO.175 连接两个表
组合两个表
思路
代码
# Write your MySQL query statement below
select p.FirstName, p.LastName, a.City, a.State
from Person p left join Address a on p.PersonId = a.PersonId;
题目:第二大高薪
思路
排除掉最高薪剩下的最高薪;
代码
# Write your MySQL query statement below
select max(Salary) SecondHighestSalary from Employee where Salary <> (select max(Salary) from Employee);
题目:超过经理收入的员工
思路
- 个表起两个别名
- where 选择符合要求的字段
代码
select e1.Name as Employee
from Employee e1,Employee e2 where e1.ManagerId = e2.Id and e1.Salary > e2.Salary;
本文来自博客园,作者:jucw,转载请注明原文链接:https://www.cnblogs.com/Jucw/p/15735901.html