SQL-Employees Earning More Than Their Managers


 

思路:

今天复习数据库突然想起来leetcode上数据库的题目,就找来做了

(1)给表取别名

格式见code,这在自身连接的时候是很有必要的

(2)自身连接

from语句后面相当于接了“一张表”,如果是多个表,就相当于形成了他们的笛卡尔积

然后通过where语句选择出所需要的行,通过头上的select语句选出相应的列


 

# Write your MySQL query statement below
select a.Name from Employee as a,Employee as b
where a.ManagerId = b.Id and a.Salary > b.Salary
posted @ 2015-12-21 14:52  Miller_S  阅读(168)  评论(0编辑  收藏  举报