繁体   English   中英

关系不存在PostgreSQL

[英]Relation Does Not Exist PostgreSQL

我正在开发LeetCode程序,但似乎无法在PostgreSQL中工作。 问题是找到一个薪水比其经理高的员工。 表格如下:

| Id | Name  | Salary | ManagerId |

| 1  | Joe   | 70000  | 3         |

| 2  | Henry | 80000  | 4         |

| 3  | Sam   | 60000  | NULL      |

| 4  | Max   | 90000  | NULL      |

我为此付出了一些努力,因为这是我正在尝试的代码:

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

但是我不断收到这样的错误

错误:关系“ e2”不存在。

谁能告诉我这是为什么,以及我需要做些什么才能使它起作用?

谢谢!

正确的连接语法应为:

select e."Name" as Employee
from "Employee" as e
inner join employee e2 on e."ManagerId" = e2."Id"
and e."Salary" > e2."Salary"

表名来inner join ,你需要涉及每个员工向他们的经理,所以连接条件应e."ManagerId" = e2."Id"

最后一点:

在PostgreSQL中,表名和列名不区分大小写,除非用引号引起来。

所以, e.managerid相当于e.ManagerId ,但不等同于e."ManagerId"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM