现在有如下员工关系数据库
Employee (employee_ name, street, city)
Works (employee_ name, company_ name, salary)
Company (company_ name, city)
Manages (employee_ name, manager_ name)
用SQL语句实现下面题目
点击下载示例数据库(Access版本)
1,找出比HP的员工收入都高的所有员工的姓名;
select employee_name from works where salary >(select max(salary) from works where company_name='HP')
2,找出与其经理居住在同一城市同一街道的员工的姓名;
select E.employee_name from Employee as E inner join Manages on E.employee_name=Manages.employee_name inner join Employee M on M.employee_name=Manages.manager_name where E.stree=M.stree and E.city=M.city
3,找出员工最多的公司
select top 1 company_name from works group by company_name order by count(*) desc
4,找出平均工资高于HP平均工资的所有公司
select company_name from works group by company_name having avg(salary)>(select avg(salary) from works where company_name='HP')
5,找出工资高于其所在公司员工平均工资的所有员工;
select employee_name from works as W1 where salary>(select avg(salary) from works group by company_name having company_name=W1.company_name)
[此贴子已经被作者于2006-11-7 14:48:34编辑过]