MySQL 练习记录

Posted by WHZ0325 on 2023-11-18, Viewed times

#175. 组合两个表

select 得到的列,from 后用 left join 拼接,on 后是拼接规则。

末尾分号

1
2
3
select firstName, lastName, city, state
from Person left join Address
on Person.PersonId = Address.PersonId;

#181. 收入超过经理的用户

select 的 from 后跟两个会得到笛卡尔乘积,应当用 and 连接筛选条件,由于 select 只要头为 Employee 的 name 要用 as。

1
2
3
select a.name as Employee
from Employee as a, Employee as b
where a.managerId = b.id and a.salary > b.salary;