Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 错误:对“表”的FROM子句项的引用无效;r";_Sql_Postgresql_Join - Fatal编程技术网

Sql 错误:对“表”的FROM子句项的引用无效;r";

Sql 错误:对“表”的FROM子句项的引用无效;r";,sql,postgresql,join,Sql,Postgresql,Join,我正在运行以下查询,但在“r.teamId”上出现无效引用错误。关于这一点,我找到了很多答案,但大多数都建议将隐式连接转换为显式连接。在我的例子中,我认为查询已经显式连接。如何解决此错误 select r.teamId,sum(r.amount),count(r.id),sum(r.distance),s.start_date from runs r inner join ( SELECT team.id,league.start_date,league.end_date FROM league

我正在运行以下查询,但在“r.teamId”上出现无效引用错误。关于这一点,我找到了很多答案,但大多数都建议将隐式连接转换为显式连接。在我的例子中,我认为查询已经显式连接。如何解决此错误

select r.teamId,sum(r.amount),count(r.id),sum(r.distance),s.start_date
from runs r inner join ( SELECT team.id,league.start_date,league.end_date FROM league join team 
ON league.id =team.league_id where r.teamId = team.id) s
on s.id = r.teamId
where r.teamId IS Not NULL 
group by r.teamId,s.start_date
order by sum(r.amount) desc; 

去掉无用的括号和派生表,您就不会被错误的别名所迷惑:

select r.teamId,
       sum(r.amount),
       count(r.id),
       sum(r.distance), 
       l.start_date
from runs r 
  join team on r.teamid = team.id 
  join league l on l.id = team.league_id
where r.teamId IS Not NULL 
group by r.teamId, l.start_date
order by sum(r.amount) desc; 

将其更改为
r.teamId
r.“teamId”
。你的问题是报价。我投票以一个简单的排版错误来结束这类问题。只需删除
,其中“r.teamId”=team.id
——您不能像这样关联子查询。您已经在您的
join
…@GordonLinoff r中执行了此操作。“teamId”仅用于突出显示错误发生情况。@NishantKhandelwal-您的编辑不会改变无法像这样关联子查询的事实。从子查询中删除
,其中r.teamId=team.id
,您的查询应该可以工作。