面试有个SQL试题如下:
Given a basic HR table with info for each employee:
Employees
{
String Name
String ID
String Manager_ID
Int Salary
String Department
}
For each department, find the number of employees who make more money than their immediate manager.
我这么写对吗?
Select Department, count (*) as “number of employees”
From Employees
Where Salary > Manager_ID_Salary
Group by Department
不对的话请指正.SQL学过但很少用.
请教SQL高手一个问题,先谢了
所有跟帖:
•
不对,要self join 一次
-Jamesxu-
♂
(0 bytes)
()
03/07/2008 postreply
12:44:39
•
我说错了,不需要self join
-Jamesxu-
♂
(0 bytes)
()
03/07/2008 postreply
12:47:57
•
self join还是需要的。。。。。我真行-_-!!
-Jamesxu-
♂
(0 bytes)
()
03/07/2008 postreply
12:49:24
•
:)
-水瓶小猪-
♀
(0 bytes)
()
03/07/2008 postreply
12:57:30
•
这些东西SQL的基础的东西, 估计你是有段时间没用了..
-gsmarketing-
♀
(0 bytes)
()
03/07/2008 postreply
12:59:37
•
是啊,多年前学过,几年前用过也是写很简单的QUERY,哎...
-水瓶小猪-
♀
(0 bytes)
()
03/07/2008 postreply
13:05:29
•
回复:wrong!
-sub101-
♂
(34 bytes)
()
03/07/2008 postreply
12:45:25
•
回复:请教SQL高手一个问题,先谢了
-sub101-
♂
(192 bytes)
()
03/07/2008 postreply
12:48:40
•
回复:请教SQL高手一个问题,先谢了
-布衣之才-
♂
(182 bytes)
()
03/07/2008 postreply
12:49:51
•
鞠躬,多谢楼上三位这么快的回复,俺知道方向了,去恶补去了:)
-水瓶小猪-
♀
(0 bytes)
()
03/07/2008 postreply
12:56:26
•
这是什麽公司?待遇这么好
-胡说之-
♂
(79 bytes)
()
03/07/2008 postreply
15:12:05