【问题标题】:SQL Inner join on select statements选择语句上的 SQL 内连接
【发布时间】:2010-12-28 18:36:01
【问题描述】:

我正在尝试对这样的 select 语句进行内部联接:

select *
from (select* from bars  where rownum <= 10 )as tab1
inner join (select * from bars  where rownum <= 10 )as tab2
on tab1.close=tab2.close

我收到以下错误: ORA-00933 SQL 命令未正确结束 任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: sql oracle ora-00933


    【解决方案1】:

    只需从您的查询中删除 as

    select *
    from (select* from bars  where rownum <= 10 ) tab1
    inner join (select * from bars  where rownum <= 10 ) tab2
    on tab1.close=tab2.close
    

    【讨论】:

    • 嗨,egorius,谢谢,它成功了。我仍然不明白为什么有时 oracle 接受 as 有时不接受
    • 'As' 可以(可选地)在 COLUMN 别名之前使用。 TABLE 别名不能在前面加上“as”。例如:“select count(*) as cnt from dual d”。
    • 你可能想看看 SELECT 语法图(它很大,但定义了确切的语法):download.oracle.com/docs/cd/B10501_01/server.920/a96540/…
    【解决方案2】:

    我相信错误来自您需要分号来结束语句。否则,选择对我来说看起来不错。

    【讨论】:

      【解决方案3】:
      select * from 
      ((select* from bars  where rownum <= 10 )as tab1
      inner join (select * from bars  where rownum <= 10 )as tab2
      on tab1.close=tab2.close)
      

      【讨论】:

        【解决方案4】:

        只需在 ')' 和 'as' 之间添加一个空格:

        select * from (select* from bars  where rownum <= 10 ) as tab1
         inner join
         (select * from bars  where rownum <= 10 ) as tab2
         on
         tab1.close=tab2.close
        

        【讨论】:

          猜你喜欢
          • 2010-12-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-22
          相关资源
          最近更新 更多