gpt4 book ai didi

SQL 更新帮助

转载 作者:行者123 更新时间:2023-12-04 19:15:17 27 4
gpt4 key购买 nike

我有一个非常简单的问题,是否可以仅使用一个更新语句用新值更新表。

例如,我有一个包含作者、标题、日期、受欢迎程度的表格。现在我得到了一些新数据,其中有作者姓名、标题对应的新流行度。我现在如何在一条语句中更新表格。请注意,作者和标题不是唯一的。

最佳答案

您可以使用 Oracle 的 MERGE 语句在一条语句中完成:

MERGE DestinationTable target
USING (
Select 'Briggs' Author, 'My Next Master' Title, 6 Popularity
Union All Select 'Millis', 'Man up, Nut head', 3
) Z
ON Z.Author = target.Author
And Z.Title = target.Title
WHEN MATCHED THEN
UPDATE SET target.Popularity = Z.Popularity
WHEN NOT MATCHED THEN
Insert(Author, Title, Popularity) Values(Z.Author, Z.Title, Z.Popularity);

Oracle's MERGE statement

关于SQL 更新帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3001924/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com