将隐式联接转换为显式联接
Convert Implicit Join to Explicit
我在下面有一个查询似乎同时隐式连接了 3 个表,我正在尝试重写它以使用显式连接,但我无法理解它,它似乎是连接一个连接的列依赖于尚未完成的连接。
这是只有隐式连接才能适应的场景吗?
我遇到的问题是和平:
AND((t.object_type = 'SOME_VALUE' and i.pro_prod_id=400 and i.gbcert_id || '-Packing' = ta.gbcert_id)
OR (t.object_type in ('V1','V2','V3') and i.gbcert_unique_id = ta.gbcert_id))
可以看到我们是根据t.object_type = 'SOME_VALUE'
还是t.object_type in ('V1','V2','V3')
来决定Join的列
但我还没有那个值,因为 t 上还没有 Join,对我来说它就像是鸡问题之前的鸡蛋..
这是查询的更完整版本:
FROM TRANSACTION t, USG_Award ta,
inbox i,
stores s,
clients cl,
client_types ct
WHERE ct.client_type = cl.client_type
AND ct.usg_aggregation_client IS NULL
AND i.orig_store_code = s.sto_store_code
AND i.orig_store_code = cl.store_code
and ((t.object_type = 'SOME_VALUE' and i.pro_prod_id=400 and i.gbcert_id || '-Pack' = ta.gbcert_id)
OR (t.object_type in ('V1','V1','V1') and i.gbcert_unique_id = ta.gbcert_id))
AND ta.fk_usg_tx = t.pk_usg_tx
此查询以其当前形式运行,它是我未编写的遗留代码。
代码已清理。
您可以将此类条件移动到 ON
子句中:
FROM TRANSACTION t JOIN
USG_Award ta
ON ta.fk_usg_tx = t.pk_usg_tx JOIN
inbox i
ON ((t.object_type = 'SOME_VALUE' and i.pro_prod_id = 400 and i.gbcert_id || '-Pack' = ta.gbcert_id) OR
(t.object_type in ('V1', 'V1', 'V1') and i.gbcert_unique_id = ta.gbcert_id)
)JOIN
stores s
ON i.orig_store_code = s.sto_store_code JOIN
clients cl
ON i.orig_store_code = cl.store_codeJOIN
client_types ct
ON ct.client_type = cl.client_type
WHERE ct.usg_aggregation_client IS NULL
我在下面有一个查询似乎同时隐式连接了 3 个表,我正在尝试重写它以使用显式连接,但我无法理解它,它似乎是连接一个连接的列依赖于尚未完成的连接。
这是只有隐式连接才能适应的场景吗?
我遇到的问题是和平:
AND((t.object_type = 'SOME_VALUE' and i.pro_prod_id=400 and i.gbcert_id || '-Packing' = ta.gbcert_id)
OR (t.object_type in ('V1','V2','V3') and i.gbcert_unique_id = ta.gbcert_id))
可以看到我们是根据t.object_type = 'SOME_VALUE'
还是t.object_type in ('V1','V2','V3')
但我还没有那个值,因为 t 上还没有 Join,对我来说它就像是鸡问题之前的鸡蛋..
这是查询的更完整版本:
FROM TRANSACTION t, USG_Award ta,
inbox i,
stores s,
clients cl,
client_types ct
WHERE ct.client_type = cl.client_type
AND ct.usg_aggregation_client IS NULL
AND i.orig_store_code = s.sto_store_code
AND i.orig_store_code = cl.store_code
and ((t.object_type = 'SOME_VALUE' and i.pro_prod_id=400 and i.gbcert_id || '-Pack' = ta.gbcert_id)
OR (t.object_type in ('V1','V1','V1') and i.gbcert_unique_id = ta.gbcert_id))
AND ta.fk_usg_tx = t.pk_usg_tx
此查询以其当前形式运行,它是我未编写的遗留代码。 代码已清理。
您可以将此类条件移动到 ON
子句中:
FROM TRANSACTION t JOIN
USG_Award ta
ON ta.fk_usg_tx = t.pk_usg_tx JOIN
inbox i
ON ((t.object_type = 'SOME_VALUE' and i.pro_prod_id = 400 and i.gbcert_id || '-Pack' = ta.gbcert_id) OR
(t.object_type in ('V1', 'V1', 'V1') and i.gbcert_unique_id = ta.gbcert_id)
)JOIN
stores s
ON i.orig_store_code = s.sto_store_code JOIN
clients cl
ON i.orig_store_code = cl.store_codeJOIN
client_types ct
ON ct.client_type = cl.client_type
WHERE ct.usg_aggregation_client IS NULL