【发布时间】:2018-02-19 20:18:33
【问题描述】:
我正在尝试将这两个查询放在一起,但我不确定如何。我正在尝试将同一预算表中的值从去年的版本复制到今年的版本,基于它们具有相同的帐户和工作订单。
update tablename
set depreciation = x.depreciation,
profile = x.profile,
description = x.description
where version = '2019OP'
and account = x.account
and workorder = x.workorder
(select * from tablename where version = '2018OP' and batch = '') x
我在这个论坛上发现了与此类似的其他问题,但我找不到适合我的答案。
谢谢
编辑 - 这是 SQL Server 2012,兼容级别是 SQL Server 2008(100) 在 SSMS 中使用 SQL
【问题讨论】:
-
您使用的是什么 RDBMS? SQL Server、MySQL、Oracle、Postgres 等?它们的语法略有不同。
-
以下答案可能有效,也可能无效,因为您没有指定。一旦您让我们知道您正在使用哪个 RDBMS,我们就可以相应地投票和反对。
标签: sql join sql-update