问题:
显示所有员工的last_name,薪水和工作,这些员工的收入超过美国境外每个部门的所有最低薪员工。 从此查询中排除总裁和副总裁。 (使用子查询/连接)
我不确定如何正确使用子查询来正确构建
这就是我的尝试:
SELECT last_name, salary, job_id
FROM employees join locations
USING(department_id)
WHERE job_id <> ANY (SELECT *
FROM employees
WHERE job_id <> 'AD_PRES' OR job_id <> 'AD_VP')
AND salary >
(SELECT MIN(salary)
FROM employees
WHERE country_id <> 'US');
任何有关如何正确构建此问题的帮助表示赞赏。谢谢。
答案 0 :(得分:2)
LAST_NAME SALARY JOB_ID
------------------------- ---------- ----------
Hartstein 13000 MK_MAN
Banda 6200 SA_REP
Johnson 6200 SA_REP
Ande 6400 SA_REP
Lee 6800 SA_REP
Sewall 7000 SA_REP
Tuvault 7000 SA_REP
Marvins 7200 SA_REP
Bates 7300 SA_REP
Smith 7400 SA_REP
Cambrault 7500 SA_REP
Doran 7500 SA_REP
Smith 8000 SA_REP
Olsen 8000 SA_REP
Livingston 8400 SA_REP
Taylor 8600 SA_REP
Hutton 8800 SA_REP
Hall 9000 SA_REP
McEwen 9000 SA_REP
Sully 9500 SA_REP
Bernstein 9500 SA_REP
Greene 9500 SA_REP
Fox 9600 SA_REP
Bloom 10000 SA_REP
Tucker 10000 SA_REP
King 10000 SA_REP
Zlotkey 10500 SA_MAN
Vishney 10500 SA_REP
Cambrault 11000 SA_MAN
Abel 11000 SA_REP
Ozer 11500 SA_REP
Errazuriz 12000 SA_MAN
Partners 13500 SA_MAN
Russell 14000 SA_MAN
<强>输出强>:
SELECT last_name,
salary,
job_id
FROM employees e
INNER JOIN
departments d
ON ( d.department_id = e.department_id )
INNER JOIN
locations l
ON ( d.location_id = l.location_id )
WHERE e.job_id NOT IN ( 'AD_PRES', 'AD_VP' )
AND l.country_id <> 'US'
AND e.salary > ANY( SELECT salary
FROM employees ee
WHERE ee.department_id = e.department_id );
查询2 - 不使用分析函数:
AND e.salary > ( SELECT MIN( salary )
FROM employees ee
WHERE ee.department_id = e.department_id );
或
{{1}}
答案 1 :(得分:0)
SELECT
last_name, salary, job_id
FROM employees a
INNER JOIN locations b ON a.department_id = b.department_id
WHERE a.job_id NOT IN (
SELECT job_id
FROM employees
WHERE
( job_id <> 'AD_PRES' OR job_id <> 'AD_VP' ) AND
salary > (
SELECT MIN(salary)
FROM employees
WHERE country_id <> 'US'
)
);
作品?