2013-05-09 53 views
1

我在问这个问题之前已经搜索过这个网站,但是并没有发现有关的东西。我确信这是一个荒谬的基本错误,我只从0个计算机背景研究Oracle SQL约4个月。我计划在本月底结束1z0-051,以便遍历所有章节。在本条款中,我试图找到薪水高于最低薪酬职位(CLERK)平均工资的雇员的姓名,职位,薪水,部门和城市。我不断收到Missing Keyword?JOIN语法中缺少关键字

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 
+2

where子句通常在连接后出现。 – HLGEM 2013-05-09 20:49:31

回答

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 ... 
+0

非常感谢 – 2013-05-09 21:46:07

0

一个where条款后,你不能有一个join条款

0

FROM雇员e JOIN工作j < <你错过了员工和工作之间的“ON”条款>> WHERE工资

此外,在所有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.