2

在提出问题之前我已经搜索了该网站,但没有遇到相关的内容。我确信这是一个可笑的基本错误,我只从 0 计算机背景研究 Oracle SQL 大约 4 个月。我计划在本月底参加 1z0-051,因此请阅读所有章节。在这个条款中,我试图获取工资高于最低工资职位(CLERK)平均工资的员工的姓名、职务、工资、部门和城市。我不断收到缺少关键字?

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
4

3 回答 3

4

你有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 ...
于 2013-05-09T20:51:52.783 回答
0

join子句后不能有where子句

于 2013-05-09T20:52:11.077 回答
0

FROM employees e JOIN jobs j <<你在这里缺少员工和工作之间的“ON”子句>> WHERE薪水

此外,将 WHERE 子句移到所有 JOIN 之后。

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.
于 2013-05-09T20:52:40.373 回答