[英]Relation Does Not Exist PostgreSQL
I am working on a LeetCode program that I cannot seem to get to work in PostgreSQL. 我正在开发LeetCode程序,但似乎无法在PostgreSQL中工作。 The problem is to find an employee with a salary greater than their manager. 问题是找到一个薪水比其经理高的员工。 Here is the table: 表格如下:
| Id | Name | Salary | ManagerId |
| 1 | Joe | 70000 | 3 |
| 2 | Henry | 80000 | 4 |
| 3 | Sam | 60000 | NULL |
| 4 | Max | 90000 | NULL |
I've struggled with this for a little bit because this is the code that I am trying: 我为此付出了一些努力,因为这是我正在尝试的代码:
select e.Name as Employee
from Employee as e
,Employee as e2
inner join e2 on e.Id = e2.Id
and e.Salary > e2.Salary
But I keep getting the error that 但是我不断收到这样的错误
ERROR: relation "e2" does not exist. 错误:关系“ e2”不存在。
Can anyone tell me why this is and what I need to do to get this to work? 谁能告诉我这是为什么,以及我需要做些什么才能使它起作用?
Thanks! 谢谢!
The proper join syntax should be: 正确的连接语法应为:
select e."Name" as Employee
from "Employee" as e
inner join employee e2 on e."ManagerId" = e2."Id"
and e."Salary" > e2."Salary"
the table name comes after the inner join
, and you need to relate each employee to their manager, so the join condition should be e."ManagerId" = e2."Id"
表名来后的inner join
,你需要涉及每个员工向他们的经理,所以连接条件应e."ManagerId" = e2."Id"
One last note: 最后一点:
In PostgreSQL, table & column names are case insensitive, unless they are quoted. 在PostgreSQL中,表名和列名不区分大小写,除非用引号引起来。
so, e.managerid
is equivalent to e.ManagerId
but not equivalent to e."ManagerId"
所以, e.managerid
相当于e.ManagerId
,但不等同于e."ManagerId"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.