1

我正在尝试使用以下代码创建多对多的子查询。

    SELECT e.ep_suragate_pk  FROM episode e 
    JOIN (
      SELECT n.name FROM actor n 
      JOIN episode_actor ea 
      ON n.act_suragate_pk = ea.act_suragate_pk
      ) ep_act 
    ON ep_act.ep_suragate_pk = e.ep_suragate_pk;

我收到 ORA-00904: invalid indentifier 错误,但所有列都存在。

     episode
     -------
     ep_suragate_pk


     episode_actor
     -------------
     ep_suragate_pk
     act_suragate_pk


     actor
     -----
     act_suragate_pk

如果有人可以帮助我了解我哪里出错了,我将不胜感激。谢谢。

4

4 回答 4

3

子查询需要选择列ea.ep_suragate_pk才能解决无效标识符问题。尚不确定这是否会得到您想要的结果。

于 2013-05-01T09:14:11.330 回答
2

内部查询

   (
  SELECT n.name FROM actor n 
  JOIN episode_actor ea 
  ON n.act_suragate_pk = ea.act_suragate_pk
  ) ep_act 

没有用于加入的 p_suragate_pk 列

  ep_act 
ON ep_act.ep_suragate_pk = e.ep_suragate_pk;

所以你可以像这样修改

SELECT e.ep_suragate_pk  FROM episode e 
JOIN (
  SELECT n.name,n.act_suragate_pk FROM actor n 
  JOIN episode_actor ea 
  ON n.act_suragate_pk = ea.act_suragate_pk
  ) ep_act 
ON ep_act.ep_suragate_pk = e.ep_suragate_pk;
于 2013-05-01T09:16:20.733 回答
2

你不需要所有这些子查询

select  e.ep_suragate_pk  
from    episode e  , episode_actor ea , actor n
where   ea.ref_id = e.ep_suragate_pk
and     n.act_suragate_pk = ea.act_suragate_pk
于 2013-05-01T15:34:41.440 回答
1

应选择用于加入的列。所以试试:

SELECT e.ep_suragate_pk  FROM episode e 
JOIN (
  SELECT n.name, ref_id FROM actor n 
  JOIN episode_actor ea 
  ON n.act_suragate_pk = ea.act_suragate_pk
  ) ep_act 
ON ep_act.ref_id = e.ep_suragate_pk;
于 2013-05-01T09:20:48.723 回答