[英]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.