如何在自联接中使用组功能?

时间:2016-07-09 08:12:52

标签: oracle join subquery

我想将Subquery转换为Join,以下是子查询

SELECT employee_id, last_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);

我写了以下加入,但我得到" ORA-00934:这里不允许组功能"错误

SELECT e.employee_id,
  e.last_name,
  e.salary
FROM employees e
INNER JOIN employees average
ON(e.salary>AVG(average.salary));

1 个答案:

答案 0 :(得分:0)

你可以像

一样使用它
SELECT e.employee_id,
  e.last_name,
  e.salary
FROM employees e
INNER JOIN (select AVG(salary) salary from employees ) average
ON (e.salary > average.salary)
Group by e.employee_id;