这是我今年的甲骨文家庭作业的最后一个问题,我无法弄清楚哪里开始..必须是一个糟糕的大脑日。
有人可以帮我这个吗?
使用WITH子句编写SELECT语句以列出那些最高工资超过整个公司最高工资一半的工作的job_title。将子查询命名为MAX_CALC_SAL。命名结果JOB_TITLE和JOB_TOTAL中的列,并按JOB_TOTAL的降序对结果进行排序。 提示:检查作业表。您需要加入JOBS和EMPLOYEES才能显示job_title。
谢谢!
这就是我到目前为止......
WITH MAX_CALC_SAL AS (
SELECT e.salary, SUM(e.salary) AS tot_salary
FROM employees e JOIN jobs j
ON e.job_id = j.job_title
GROUP BY j.job_title
),
avg_cost AS (
SELECT SUM(e.salary)/COUNT(*) AS avg_salary
FROM e.employee
)
SELECT *
FROM e.employee
WHERE avg_salary > (SELECT max_salary / 2
FROM j.jobs)
ORDER BY job_total
答案 0 :(得分:1)
您正在寻找类似的东西:
WITH max_calc_sal
AS (SELECT job_id,
j.job_title,
MAX(e.salary) AS job_total
FROM jobs j
INNER JOIN employees e
USING (job_id)
GROUP BY job_id,
j.job_title)
SELECT job_title,
job_total
FROM max_calc_sal
WHERE job_total > (0.5 * SELECT MAX(job_total)
FROM max_calc_sal)
ORDER BY job_total DESC;
答案 1 :(得分:0)
使用WITH
子句定义的名称不会自动出现在您的最终查询中。它们像派生表一样工作,因此您必须从中选择或加入它们才能获取数据。
WITH my_with_table AS (SELECT 9 AS X FROM DUAL)
SELECT X FROM my_with_table;