SQL Teradata 更新连接语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9229582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Teradata update join syntax
提问by oscilatingcretin
I've tried a few examples I've seen on the internet, but I can't seem to figure them out. This is a Teradata database.
我已经尝试了一些我在互联网上看到的例子,但我似乎无法弄清楚。这是一个 Teradata 数据库。
I have TableA that has CustomerId and DepartmentId.
我有包含 CustomerId 和 DepartmentId 的 TableA。
I have TableB that also CustomerId and DepartmentId.
我有还有 CustomerId 和 DepartmentId 的 TableB。
I know this structure is not practical, but this is a highly non-normalized database that we took over from an offshore development team and we have to work with what we have.
我知道这种结构不实用,但这是一个高度非规范化的数据库,我们从一个离岸开发团队接手,我们必须使用我们拥有的东西。
What I want to do is join TableA and TableB on the CustomerId then set the DepartmentId of TableB to what's in TableA. I would greatly appreciate the proper syntax.
我想要做的是在 CustomerId 上加入 TableA 和 TableB,然后将 TableB 的 DepartmentId 设置为 TableA 中的内容。我将不胜感激正确的语法。
回答by Lenin Raj Rajasekaran
UPDATE A
FROM TableA A, TableB B
SET DepartmentId = B.DepartmentId
WHERE A.CustomerId = B.CustomerId