4

我正在尝试实现类似于 H2 中描述的内容:

更新内连接?

update tlegacy lca set lca.pr_dato = ca.calc_holdings_date
... from tca ca inner join tdd dd on ...

我得到错误:在 H2 中找不到列“CA.CALC_HOLDINGS_DATE”。

“缺失”字段当然存在。我尝试了许多变体,但都没有运气。H2 是否支持这种更新从许多其他联接表中收集的表中的值的方式?最终这应该在 IBM DB2 上运行。那里支持吗?

4

1 回答 1

8

对于 H2,有两种选择。第一个适用于所有数据库:

update tlegacy lca set 
  lca.pr_dato = (select ca.calc_holdings_date ... from tca ca where ...)
  where lca.id in (select ca.id from tca where ...)

第二个选项是使用非标准的MERGE语句。如果尚不存在具有此键的行,它将插入新行。

merge into tlegacy(pr_dato) key(id) 
  select ca.calc_holdings_date, ca.id from tca ca where ...
  and exists (select * from tlegacy where ...)
于 2012-03-02T15:44:48.723 回答