在主查询的where条件中检索子查询列时出错

error while Retrieving the subquery column in where condition to main query

我正在尝试检索在 Oracle SQL 的 where 条件中使用的子查询中的列。我面临 ORA-00904 无效标识符错误。下面是查询。有人可以解决吗

试图在子查询 select ev.type 中检索 ev.type , ev.fil_path , ev.fil_path,ev.test_path 来自 effortvariation ev

我试过给别名,但没有被接受。

select
   ev.fil_path,
   ev.tes_path,
   sp.uname,
   sp.pwd,
   s.desc,
   sp.option,
   oq.master_id,
   oq.status
from onlineQuery oq

inner join supporttask s

    on oq.sq =s.seq

inner join securityports sp

   on sp.sq=oq.sq

where sp.type in 
             (select ev.type , ev.fil_path,ev.test_path from effortvariation ev
             where ev.team =
                        (select team from allTeams where id ='k238')
             and ev.name ='qa'
              )
and sp.acct='active'
select * from onlineQuery oq --your_columns
 inner join supporttask s
  on oq.sq=s.seq
 inner join securityports sp
  on sp.sq=oq.sq
where exists 
(select 1 from effortvariation ev 
 inner join allteams t
  on ev.team=t.team
where ev.name='qa' and t.id='k238')
and sp.acct='active'

如果您使用SQL*Plus,它将指向确切发生错误的地方。例如:

SQL> select *
  2  from employee
  3  where 1 = 1
  4    and id = 23;
  and id = 23
      *                                 --> see? ID is invalid
ERROR at line 4:
ORA-00904: "ID": invalid identifier

ORA-00904 通常 表示table 中不存在具有这样名称的列。因此,如果我将其更改为名称有效的列:

SQL> c/id/empno
  4*   and empno = 23
SQL> /

no rows selected

SQL>

没有更多错误(好的,没有返回任何内容,但这不是 错误)。

我建议您也这样做,找出问题所在,检查 table,修复列名称。如果我们知道 table 的描述,我们可以提供帮助,但是 - 我们不知道,您从未发布过该信息。

将子查询及其所有返回的列移动到 FROM 子句,然后 JOIN 它。

select
   ev.fil_path,
   ev.tes_path,
   sp.uname,
   sp.pwd,
   s.desc,
   sp.option,
   oq.master_id,
   oq.status
from onlineQuery oq

inner join supporttask s

    on oq.sq =s.seq

inner join securityports sp

   on sp.sq=oq.sq

INNER JOIN
             (select type , fil_path,test_path from effortvariation
             where team =
                        (select team from allTeams where id ='k238')
             and name ='qa'
              ) ev ON ev.type = sp.type
WHERE sp.acct='active'