JOIN语法中缺少关键字

时间:2013-05-09 20:45:39

标签: sql oracle ora-00905

我在询问问题之前搜索了网站,但没有发现相关的问题。我确信这是一个荒谬的基本错误,我只是从0计算机背景研究Oracle SQL大约4个月。我本打算在本月底的1z0-051进行所有章节的讨论。在本条款中,我试图获得薪水高于最低薪酬职位(CLERK)平均薪水的员工的姓名,头衔,薪水,部门和城市。我不断收到Missing Keyword?

SELECT e.first_name,
  e.last_name,
  j.job_title,
  e.salary,
  d.department_name,
  l.city
FROM employees e
JOIN jobs j
WHERE salary >
  (SELECT AVG(salary) FROM employees WHERE job_id LIKE '%CLERK%'
  ) ON e.job_id = j.job_id
JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id
ORDER BY salary

3 个答案:

答案 0 :(得分:2)

您有JOIN - WHERE - ON序列错误。

应该是这样的(假设WHERE 是您加入条件的一部分):

FROM employees e
JOIN jobs j ON e.job_id = j.job_id
....
....
WHERE e.salary >
  (SELECT AVG(salary) FROM employees WHERE job_id LIKE '%CLERK%')
ORDER BY ...

答案 1 :(得分:0)

你不能在join条款

之后有一个where子句

答案 2 :(得分:0)

来自员工e 加入工作j   <<你错过了员工和工作之间的“ON”条款>> 薪水

另外,在所有JOIN之后移动WHERE子句。

select
      fields
   from
      table
         join
            join "ON" clause
         join
            join "ON" clause
   where
      some condition
   group by
      whatever grouping if aggregates
   order by
      if you want something certain order.