如何将此相关子查询转换为 Vertica 友好的非相关查询
How to convert this correlated sub query to Vertica friendly non correlated query
我有以下 SQL 服务器查询,需要将其转换为 Vertica 查询。
现在的问题是 vertica 不支持多级相关子查询,所以在我的示例中 t3.a = t1.a
不起作用
select * from t1
where not exists (
select * from t2
where t2.y = t1.y
and t2.x in (
select top 1 x from t3
where t3.z = t2.z
and t3.a = t1.a
order by t3.b
)
)
谁能帮我做这个?
Vertica 不支持超过 1 级的相关子查询,您应该将它们转换为 JOIN。
它也不支持 TOP x 子句,请改用 LIMIT x。
像这样:
SELECT t1.*
FROM t1
LEFT JOIN t2 ON t1.y = t2.y
WHERE t2.y IS NULL
AND t2.x IN
(SELECT t3.x
FROM t3
JOIN t2 ON t3.z = t2.z
JOIN t1 ON t3.a=t1.a
ORDER BY t3.b LIMIT 1);
我有以下 SQL 服务器查询,需要将其转换为 Vertica 查询。
现在的问题是 vertica 不支持多级相关子查询,所以在我的示例中 t3.a = t1.a
不起作用
select * from t1
where not exists (
select * from t2
where t2.y = t1.y
and t2.x in (
select top 1 x from t3
where t3.z = t2.z
and t3.a = t1.a
order by t3.b
)
)
谁能帮我做这个?
Vertica 不支持超过 1 级的相关子查询,您应该将它们转换为 JOIN。
它也不支持 TOP x 子句,请改用 LIMIT x。
像这样:
SELECT t1.*
FROM t1
LEFT JOIN t2 ON t1.y = t2.y
WHERE t2.y IS NULL
AND t2.x IN
(SELECT t3.x
FROM t3
JOIN t2 ON t3.z = t2.z
JOIN t1 ON t3.a=t1.a
ORDER BY t3.b LIMIT 1);