此查询中我收到ORA-00904无效标识符错误
SELECT
tab1."col1" AS ID,
tab1."col4" AS Name,
tab1."col5" AS Place,
(SELECT SUBSTR (SYS_CONNECT_BY_PATH (one_row , ';'), 2) myConString
FROM (SELECT tab2."col3" || ',' || tab2."col4" AS one_row,
ROW_NUMBER () OVER(ORDER BY tab2."col1") rn,
COUNT (*) OVER () cnt
FROM dbo."table2" tab2
WHERE tab2."col1" = tab1."col1"
AND tab2."col2" = tab1."col2")
WHERE rn = cnt
START WITH rn = 1
CONNECT BY rn = PRIOR rn + 1)
FROM dbo."table1" tab1
WHERE tab1."col1" IN (1,2,3)
AND tab1."col2" = 1 AND tab1."col3" = 1;
在这个特定的地方
tab2."col1" = tab1."col1" AND tab2."col2" = tab1."col2"
在子查询中,我将行连接成字符串,并且效果很好,并给了我正确的结果,例如
1,100;1,200;2,150....
我认为问题在于,我尝试引用对象而不是子查询的一级,但是我无法弄清楚如何重写查询。
感谢您的帮助
答案 0 :(得分:0)
相关子查询只能引用事物one level deep。您的tab1表距离tab2表两级。
我不能完全围绕您的查询,但是您可以重写它以便在tab1和tab2之间建立联接,而不是在select子句中使用相关查询吗?