【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);

题目:超过经理收入的员工

思路

  1. 个表起两个别名
  2. where 选择符合要求的字段

代码

select e1.Name as Employee
from Employee e1,Employee e2 where e1.ManagerId = e2.Id and e1.Salary > e2.Salary;
posted @ 2021-12-27 13:32  jucw  阅读(47)  评论(0编辑  收藏  举报