2012-04-03 53 views
0

這是我今年Oracle作業的最後一個問題,我無法弄清楚哪裏開始......必須是一個糟糕的大腦日。甲骨文作業 - 我難住

有人可以幫助我嗎?

使用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

哪些問題的部分混淆嗎?你到目前爲止有什麼? – APC 2012-04-03 17:17:19

+0

更重要的是:問題是什麼? – 2012-04-03 17:30:18

回答

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; 
0

WITH條款中定義的名稱是不會自動出現在你的最終查詢。它們像派生表一樣工作,因此您必須從中選擇或與它們聯合以獲取其數據。

WITH my_with_table AS (SELECT 9 AS X FROM DUAL) 
SELECT X FROM my_with_table; 
+0

@APC我不知道我在做什麼,甚至是在正確的軌道上。 – 2012-04-03 18:03:23