gpt4 book ai didi

mysql - 返回新表,其中的行在 2 个版本之间进行了修改

转载 作者:行者123 更新时间:2023-11-29 10:39:58 26 4
gpt4 key购买 nike

我有以下结构

Table1 
ID SpecificName Value Modified
3 Drogon 73 0
4 Viserion 44 0
5 Rhaegal 70 0

Table2
ID SpecificName Value Modified
8 Drogon 87 0
9 Viserion 20 0
10 Rhaegal 70 0

我想修改修改后的列值,其中 Table1.SpecificName == Table2.SpecificName AND Table1.Value != Table2.Value 并返回类似以下内容的内容:

Table3 
SpecificName Value Modified
Drogon 87 1
Viserion 20 1
Rhaegal 70 0

如何实现这一目标?

最佳答案

要达到您想要的结果,您可以使用CASE

select t2.SpecificName, t2.value,
case when (t1.value <> t2.value) then 1
when (t1.value = t2.value) then 0
ELSE NULL
end
from table1 t1
inner join table2 t2
on t1.SpecificName = t2.SpecificName;

内连接用于假设仅需要匹配值。下面是使用上述查询根据需要生成的结果。

enter image description here

您可以查看演示here

关于mysql - 返回新表,其中的行在 2 个版本之间进行了修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45670146/

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