Netezza 是否不支持多个相关查询?
Are multiple correlated queries unsupported in Netezza?
这可能更容易用代码解释,所以我目前使用的是这样的东西:
'A' in
(
SELECT DISTINCT b.col1
FROM table b
WHERE b.ky1 = a.ky1
AND b.ky2 = a.ky2
AND b.group = a.group
AND b.rowNum < a.rowNum
)
在 where 子句中。本质上,我试图查看 A 是否是外部查询指定的行之前的任何点的值。这是独立工作的。问题是当我将以下内容添加到查询中时:
OR
'S' in
(
SELECT DISTINCT b.col1
FROM tableb b
WHERE b.ky1 = a.ky1
AND b.ky2 = a.ky2
AND b.group = a.group
AND b.rowNum < a.rowNum
)
现在,Netezza 生成以下错误消息:
ERROR: (2) This form of correlated query is not supported - consider rewriting
我觉得解决这个问题的唯一方法是进行某种连接,但我不确定如何在不产生大量重复项的情况下进行连接。有什么建议吗?
从 7.2 版开始,Netezza 中的相关子查询具有以下使用注意事项,如文档所述here。
If you choose to use correlated subqueries, keep in mind the following
restrictions on the form and placement of correlated subqueries:
- You can use correlated subqueries in WHERE clauses.
- You can use correlated subqueries in inner join conditions and with the equal join condition operator.
You can use correlated subqueries in mixed correlated expressions only in the following form:
expr(corr_columA, corr_columnB,...) = expr(local_columnX,
local_columnY,...)
You cannot use correlated subqueries in SET operations (UNION, INTERSECT, EXCEPT, and MINUS).
- You cannot use correlated subqueries in aggregates with GROUP BY and HAVING clauses.
- You cannot use correlated subqueries in ORed clauses or in CASE/WHEN expressions.
^=== You are here
- You cannot use correlated subqueries in IN lists.
- You cannot use correlated subqueries in SELECT lists.
如果将 OR 更改为 AND,您会发现查询将 运行。当然不是说它会产生你想要的结果。
您可以将其重写为 JOIN,但我需要先查看查询结构的平衡,然后才能试一试它可能是什么。
这可能更容易用代码解释,所以我目前使用的是这样的东西:
'A' in
(
SELECT DISTINCT b.col1
FROM table b
WHERE b.ky1 = a.ky1
AND b.ky2 = a.ky2
AND b.group = a.group
AND b.rowNum < a.rowNum
)
在 where 子句中。本质上,我试图查看 A 是否是外部查询指定的行之前的任何点的值。这是独立工作的。问题是当我将以下内容添加到查询中时:
OR
'S' in
(
SELECT DISTINCT b.col1
FROM tableb b
WHERE b.ky1 = a.ky1
AND b.ky2 = a.ky2
AND b.group = a.group
AND b.rowNum < a.rowNum
)
现在,Netezza 生成以下错误消息:
ERROR: (2) This form of correlated query is not supported - consider rewriting
我觉得解决这个问题的唯一方法是进行某种连接,但我不确定如何在不产生大量重复项的情况下进行连接。有什么建议吗?
从 7.2 版开始,Netezza 中的相关子查询具有以下使用注意事项,如文档所述here。
If you choose to use correlated subqueries, keep in mind the following restrictions on the form and placement of correlated subqueries:
- You can use correlated subqueries in WHERE clauses.
- You can use correlated subqueries in inner join conditions and with the equal join condition operator.
You can use correlated subqueries in mixed correlated expressions only in the following form:
expr(corr_columA, corr_columnB,...) = expr(local_columnX, local_columnY,...)
You cannot use correlated subqueries in SET operations (UNION, INTERSECT, EXCEPT, and MINUS).
- You cannot use correlated subqueries in aggregates with GROUP BY and HAVING clauses.
- You cannot use correlated subqueries in ORed clauses or in CASE/WHEN expressions. ^=== You are here
- You cannot use correlated subqueries in IN lists.
- You cannot use correlated subqueries in SELECT lists.
如果将 OR 更改为 AND,您会发现查询将 运行。当然不是说它会产生你想要的结果。
您可以将其重写为 JOIN,但我需要先查看查询结构的平衡,然后才能试一试它可能是什么。