gpt4 book ai didi

MySQL:将信息从表复制到具有相反值的另一个表

转载 作者:行者123 更新时间:2023-11-29 12:20:13 24 4
gpt4 key购买 nike

我需要将信息( bool 值)从“详细信息”表复制到“用户”表,与“相反”值一样:

表结构:“用户”表:

id     name     appear
1 John null
2 Matt null
3 jack null
4 sara null
5 sarah null

“详细信息”表:

id      user_id        appaer
1 1 false
2 2 false
3 3 true
4 4 true
5 5 true

结果“用户”表应如下所示;

id     name     appear
1 John true
2 Matt true
3 jack false
4 sara false
5 sarah false

如何做到这一点?

谢谢

最佳答案

true 然后 false 时,更新会从用户表中出现,并使用 user_id 连接这两个表

update user
set appear=(select case when details.appear='true' then 'false'
when details.appear='false' then 'true' end
from details join user
on details.user_id=users.id)

关于MySQL:将信息从表复制到具有相反值的另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140841/

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