更新选择的结果

发布于 2024-10-30 22:33:46 字数 702 浏览 1 评论 0原文

我有一个表 caxnode,其中包含字段 node_alias、node_mode、node_id 等。

在某些情况下,node_alias 被标记为“常规”以及不同 node_id 的“逻辑”。我想将相同的 node_alias 标记为“常规”和“逻辑”的条目更改为逻辑。即,如果同一个条目在表中被标记为“逻辑”并且是一个 LDOM 分区,则将“常规”更改为“逻辑”。

这是我的工作查询,用于返回我有兴趣更改的结果。

select Node_ID, Node_type, Num_of_proc, Node_Alias, Host_ID, Node_mode, Partition_Type
from CAXNODE nd
where (Node_mode = 'VIRTUAL' or Node_mode = 'REGULAR')
and Node_Alias in
    (select nd2.Node_Alias
     from CAXNODE nd2
     where nd2.Node_mode = 'LOGICAL' and Partition_Type = 'LDOM'
    ) ;

现在我想更改值以将 Node_mode 设置为“逻辑”; Partition_Type 为“LDOM”,Host_ID 为 (nd2.Host_ID); Num_of_proc 到 (nd2.Num_of_proc);

我怎样才能在一个更新声明中做到这一点?

I have a table caxnode which has fields node_alias, node_mode, node_id, etc..

In some cases, the node_alias is marked as "regular" as well as 'logical' for different node_id's. I want to change the entries for which the same node_alias is marked 'regular' as well as 'logical' to logical. i.e. change the "regular" to "logical" if the same entry is marked 'logical' in the table and is an LDOM partition ..

This is my working query to return the results that I am interested in changing..

select Node_ID, Node_type, Num_of_proc, Node_Alias, Host_ID, Node_mode, Partition_Type
from CAXNODE nd
where (Node_mode = 'VIRTUAL' or Node_mode = 'REGULAR')
and Node_Alias in
    (select nd2.Node_Alias
     from CAXNODE nd2
     where nd2.Node_mode = 'LOGICAL' and Partition_Type = 'LDOM'
    ) ;

Now I want to change the values to set Node_mode to 'LOGICAL'; Partition_Type to 'LDOM', Host_ID to (nd2.Host_ID); Num_of_proc to (nd2.Num_of_proc);

How can I do this in one update statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2024-11-06 22:33:46

简单的。删除 SELECT,并替换为 UPDATE [target],然后添加更改的 SET 列表。

--select Node_ID, Node_type, Num_of_proc, Node_Alias, Host_ID, Node_mode, Partition_Type
UPDATE nd
SET
    Node_mode = 'LOGICAL',
    Partition_Type = 'LDOM',
    Host_ID = nd2.Host_ID,
    Num_of_proc = nd2 Num_of_proc
from CAXNODE nd
where (Node_mode = 'VIRTUAL' or Node_mode = 'REGULAR')
and Node_Alias in
    (select nd2.Node_Alias
     from CAXNODE nd2
     where nd2.Node_mode = 'LOGICAL' and Partition_Type = 'LDOM'
    ) ;

Easy. Remove the SELECT, and replace with UPDATE [target], then add the SET list of changes.

--select Node_ID, Node_type, Num_of_proc, Node_Alias, Host_ID, Node_mode, Partition_Type
UPDATE nd
SET
    Node_mode = 'LOGICAL',
    Partition_Type = 'LDOM',
    Host_ID = nd2.Host_ID,
    Num_of_proc = nd2 Num_of_proc
from CAXNODE nd
where (Node_mode = 'VIRTUAL' or Node_mode = 'REGULAR')
and Node_Alias in
    (select nd2.Node_Alias
     from CAXNODE nd2
     where nd2.Node_mode = 'LOGICAL' and Partition_Type = 'LDOM'
    ) ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文