【问题标题】:i am not getting error missing keyword in my code我的代码中没有出现错误缺少关键字
【发布时间】:2021-06-18 12:53:58
【问题描述】:
select e.department_id,e.salary,d.department_name 
from employees e
join departments d
    on d.department_id=e.department_id
inner join
    (
        select department_id,max(salary) as max_sal from employees
        group by department_id
    ) as t
    on e.department_id=t.department_id
where e.salary =t.max_sal;

【问题讨论】:

  • 你在问什么?
  • 我看不出您应该在此处收到“缺少关键字”错误的任何原因。为什么你认为你应该这样做?
  • 欢迎您。唯一的潜在错误是在 t 表名之前使用 as 关键字。有些 DBMS 不想要它,但请突出显示您的错误,以便我们为您提供帮助。
  • 完全正确,但它给出错误:ORA-00905:缺少关键字 00905。00000 - 子查询别名部分的“缺少关键字”)作为 t
  • 欢迎来到 Stackoverflow!请清楚地提出问题。在发布之前尝试对其进行几次审查。尽量提供尽可能多的细节。还分享您迄今为止为解决此问题所做的工作。这将使您和其他用户的体验更好。 :)

标签: sql database oracle data-analysis


【解决方案1】:

Oracle 不支持as 为表别名,你可以试试:

select e.department_id, e.salary, d.department_name 
from employees e join
     departments d
     on d.department_id = e.department_id inner join
     (select department_id, max(salary) as max_sal
      from employees
      group by department_id
     ) t
     on e.department_id = t.department_id
where e.salary = t.max_sal;

当然,使用窗口函数编写会更好,但这回答了您提出的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 2010-10-08
    • 2016-03-12
    • 1970-01-01
    相关资源
    最近更新 更多