在SQL中更改为具有独特的SQL
拥有这个:
code IN
(
SELECT DISTINCT aaa.code
FROM ORGHEADER AS aaa
LEFT JOIN ORGRELATEDPARTY AS bbb
ON aaa.oh_pk = bbb.parent
WHERE aaa.oh_pk NOT IN
(
SELECT fu.parent
FROM ORGRELATEDPARTY fu
WHERE fu.partytype = 'MNG'
)
)
阅读这个: 在 SQL 中将 IN 更改为 EXISTS
尝试将其更改为“Exists”,但是产生了这个但它不起作用:
code EXISTS
(
SELECT *
FROM ORGHEADER AS aaa
LEFT JOIN ORGRELATEDPARTY AS bbb
ON aaa.oh_pk = bbb.pr_oh_parent
WHERE aaa.oh_pk NOT IN
(
SELECT fu.parent
FROM ORGRELATEDPARTY fu
WHERE fu.pr_partytype = 'MNG'
)
WHERE code = DISTINCT aaa.oh_code
)
错误为 3706:语法错误:需要介于“=”和“DISTINCT”关键字之间的内容。
Having this one:
code IN
(
SELECT DISTINCT aaa.code
FROM ORGHEADER AS aaa
LEFT JOIN ORGRELATEDPARTY AS bbb
ON aaa.oh_pk = bbb.parent
WHERE aaa.oh_pk NOT IN
(
SELECT fu.parent
FROM ORGRELATEDPARTY fu
WHERE fu.partytype = 'MNG'
)
)
Reading this one:
Changing IN to EXISTS in SQL
Tried to change it into "Exists", but produced this and it did not work:
code EXISTS
(
SELECT *
FROM ORGHEADER AS aaa
LEFT JOIN ORGRELATEDPARTY AS bbb
ON aaa.oh_pk = bbb.pr_oh_parent
WHERE aaa.oh_pk NOT IN
(
SELECT fu.parent
FROM ORGRELATEDPARTY fu
WHERE fu.pr_partytype = 'MNG'
)
WHERE code = DISTINCT aaa.oh_code
)
The error is 3706: Syntax error: expected something between '=' and 'DISTINCT' keyword.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经有多余的代码。
在
IN
子查询中,您从ORGHEADER
选择一列,因此LEFT
连接只会增加噪音,因为它在任何情况下都会返回ORGHEADER
中的所有行code>ORGHEADER。假设
code
属于一个别名为t
的表,您可以使用EXISTS
编写代码,如下所示这:另外,
不如果表
将不起作用。ORGRELATEDPARTY
的列parent
可能返回null
,INYou have already redundant code.
Inside the
IN
subquery you are selecting a column fromORGHEADER
, so theLEFT
join only adds noise since it returns in any case all rows fromORGHEADER
.Assuming that
code
belongs to a table aliased ast
you can write the code withEXISTS
like this:Also,
NOT IN
will not work if the columnparent
of the tableORGRELATEDPARTY
may returnnull
s.