返回信息流题干如下:
The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
+----+-------+--------+-----------+
| Id | Name | Salary | ManagerId |
+----+-------+--------+-----------+
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
+----+-------+--------+-----------+
Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
+----------+
| Employee |
+----------+
| Joe |
+----------+
我的解答1(死活都有错):
select A.Name as Employee from Employee A where A.ManagerId <> NULL and A.Salary > (select B.Salary from Employee B where B.Id = A.ManagerId)
我的解答2(ok的):
SELECT a.NAME AS Employee FROM Employee a, Employee b WHERE a.ManagerId = b.Id AND a.Salary > b.Salary;
求指点解答一哪里有问题了,感谢
这是一条镜像帖。来源:北邮人论坛 / database / #9794同步于 2016/2/12
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
钻牛角尖leetcode某题,求指点破解
ccdyh
2016/2/12镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
将 "<> NULL"改为 "is not NULL"。亲测有效。
找到一篇文章【http://argel-lj.iteye.com/blog/1219157】说到某些:
“最后两个PL/SQL下验证不正确!)由于null 为一种状态,不是一个值,故建议不适用算术逻辑符号<> ”
PS: 去掉"as Employee"也AC,貌似没有影响
明白,感谢~~
【 在 xoiiox 的大作中提到: 】
: 将 "<> NULL"改为 "is not NULL"。亲测有效。
: 找到一篇文章【http://argel-lj.iteye.com/blog/1219157】说到某些:
: “最后两个PL/SQL下验证不正确!)由于null 为一种状态,不是一个值,故建议不适用算术逻辑符号<> ”
: ...................