我在此查询中得到缺少右括号的错误。我在这里缺少什么,我看到5个左括号和5个右括号。我想做的是仅返回具有最新日期的行。
WITH snCTE AS
(
SELECT
T1.column1
,T1.column2
,T2.column3
,T2.column4
,T1.datefield
,ROW_NUMBER() OVER (PARTITION BY column1 ORDER BY datefield DESC) AS RN
FROM dBtable1 T1
LEFT OUTER JOIN dBtable2 T2 ON (T1.columnid=T2.columnid AND T1.otherfield=T2.otherfield)
WHERE EXISTS (SELECT 1 FROM dbtable3 AS T3 WHERE T3.column1 = T1.column1)
)
SELECT column1, column2, column3, column4, datefield
FROM snCTE
WHERE snCTE.RN = 1
答案 0 :(得分:5)
该错误消息具有误导性;真正的问题是Oracle在表别名中不支持AS
,而仅支持列,因此
FROM dbtable3 AS T3
应编辑为
FROM dbtable3 T3
例如:
SQL> select 1 as ONE from dual;
ONE
----------
1
SQL> select 1 as ONE from dual D;
ONE
----------
1
SQL> select 1 as ONE from dual as D;
select 1 as ONE from dual as D
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
答案 1 :(得分:0)
错误ORA-00907
的来源是在AS
中使用FROM dbtable3 AS T3
,
因为在Oracle DB中不允许使用AS
对表或子查询进行别名。
因此,只需删除该AS
关键字即可。