ORA-00904加入

时间:2015-12-14 15:52:18

标签: sql oracle view ora-00904

我正在尝试创建以下视图:

CREATE OR REPLACE VIEW AlbumDistribution AS
  SELECT Album.Album_ID,
         Album.title,
         HasTrack.tracked,
         FinishedTrack.released_title,
         SUBSTR(Album.Album_ID, -1) is_distributed_as
    FROM Album A
    JOIN HasTrack HT 
      ON HT.Album_ID = A.Album_ID 
    JOIN FinishedTrack FT
      ON HasTrack.OriginatesFrom = FT.OriginatesFrom
     AND HasTrack.tracked = FT.version;

但我收到ORA-00904错误:

 ERROR at line 6:
 ORA-00904: "HASTRACK"."TRACKED": invalid identifier

我觉得很困惑,因为我之前参考过HasTrack.tracked而且没有错误。如果我更改了语句的顺序,那么将HasTrack.OriginatesFrom = FT.OriginatesFrom最后一个然后我得到相同的错误但是对于HasTrack.OriginatesFrom。

1 个答案:

答案 0 :(得分:2)

您可以为此表和其他表定义别名。您需要在整个查询中使用别名:

CREATE OR REPLACE VIEW AlbumDistribution AS
    SELECT A.Album_ID, A.title, HT.tracked,
           FT.released_title, SUBSTR(A.Album_ID, -1) is_distributed_as
    FROM Album A JOIN
         HasTrack HT
         ON HT.Album_ID = A.Album_ID JOIN
         FinishedTrack FT
         ON HT.OriginatesFrom = FT.OriginatesFrom AND
            HT.tracked = FT.version;