[英]Oracle SQL subquery
Display employee last_name
, salary
and job
who work either in IT
or MARKETING
department and earn more than the worst paid person in the ACCOUNTING
department.显示在
IT
或MARKETING
部门工作并且收入比ACCOUNTING
部门收入最低的人多的员工last_name
、 salary
和job
。 Sort the output by the last name alphabetically.按姓氏字母顺序对输出进行排序。
My answer:我的答案:
select
last_name, salary, job_id
from
employees
where
salary > (select min(salary)
from employees
where department_id = (select department id
from departments
where department_name like'IT'
or like 'Marketing'));
Not exactly sure what you want, but it sounds something like this.不完全确定你想要什么,但听起来像这样。 Add other columns in select query as you want.
根据需要在选择查询中添加其他列。
http://sqlfiddle.com/#!9/cfb31c/5/0 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
Update更新
Same statement, reformatted.同样的语句,重新格式化。
Also removed inner
keyword and fixed on
clause, so SQL is vendor neutral, ie works on MySQL, MS SQL, Oracle, PostgreSQL, ...还删除了
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.