显示在last_name
或salary
部门工作的员工job
,IT
和MARKETING
,其收入高于{{1}中收入最低的人1}}部门。按字母顺序对输出按姓氏排序。
我的回答:
ACCOUNTING
答案 0 :(得分:1)
不完全确定你想要什么,但听起来像这样。根据需要在select query中添加其他列。
http://sqlfiddle.com/#!9/cfb31c/5/0
select e.last_name,e.salary,e.department_id from
employee e inner join department d
on e.department_id=d.department_id
where d.department_name in ('IT','MARKETING')
and e.salary > (select min(e1.salary) from employee e1
inner join department d1
where e1.department_id=d1.department_id
and d1.department_name = 'ACCOUNTING')
order by e.last_name
<强>更新强>
同一声明,重新格式化。
还删除了inner
关键字和固定on
子句,因此SQL是供应商中立的,即适用于MySQL,MS SQL,Oracle,PostgreSQL,......
select e.last_name, e.salary, e.department_id
from employee e
join department d on d.department_id = e.department_id
where d.department_name in ('IT','MARKETING')
and e.salary > ( select min(e1.salary)
from employee e1
join department d1 on d1.department_id = e1.department_id
where d1.department_name = 'ACCOUNTING' )
order by e.last_name