如何更新 table 加入自身
How to update table with join on itself
我正在尝试更新 table 中的一列,该列在自身上进行连接以过滤掉数据。
最初,这段代码是针对 SQL 服务器的,我试图将其更改为 运行 在 Vertica 中。我收到此错误:
ERROR: Syntax error at or near "inner"
update REPORT.sub_2018_ALL a
inner join REPORT.sub_2018_ALL p
on a.MBR_ID= p.MBR_ID and a.NAME = p.NAME
set RESULT = 'F'
where p.STATUS_REASON = 'Submitted' and a.REVIEW_RESULT is null
我不确定是因为别名的原因,还是当 table 加入自身时无法更新。感谢任何帮助。
我想你想要这样的东西:
update REPORT.sub_2018_ALL a
set RESULT = 'F'
where a.REVIEW_RESULT is null and
exists (select 1
from REPORT.sub_2018_ALL p
where a.MBR_ID = p.MBR_ID and
a.NAME = p.NAME and
p.STATUS_REASON = 'Submitted'
);
郑重声明,您的原始语法不适用于 SQL 服务器,尽管它可能适用于 MySQL。
我正在尝试更新 table 中的一列,该列在自身上进行连接以过滤掉数据。
最初,这段代码是针对 SQL 服务器的,我试图将其更改为 运行 在 Vertica 中。我收到此错误:
ERROR: Syntax error at or near "inner"
update REPORT.sub_2018_ALL a
inner join REPORT.sub_2018_ALL p
on a.MBR_ID= p.MBR_ID and a.NAME = p.NAME
set RESULT = 'F'
where p.STATUS_REASON = 'Submitted' and a.REVIEW_RESULT is null
我不确定是因为别名的原因,还是当 table 加入自身时无法更新。感谢任何帮助。
我想你想要这样的东西:
update REPORT.sub_2018_ALL a
set RESULT = 'F'
where a.REVIEW_RESULT is null and
exists (select 1
from REPORT.sub_2018_ALL p
where a.MBR_ID = p.MBR_ID and
a.NAME = p.NAME and
p.STATUS_REASON = 'Submitted'
);
郑重声明,您的原始语法不适用于 SQL 服务器,尽管它可能适用于 MySQL。