gpt4 book ai didi

mysql - 我想交换数据用例

转载 作者:行者123 更新时间:2023-11-29 21:19:59 26 4
gpt4 key购买 nike

table test data

 UPDATE tb_test 
set name =
( CASE
WHEN (id = 1) THEN (select DISTINCT name from tb_test where id = 2)
WHEN (

id = 2) THEN (select DISTINCT name from tb_test where id = 1)
END )

结果:

[SQL] 更新 tb_test

set name =  
( CASE
WHEN (id = 1) THEN (select DISTINCT name from tb_test where id = 2)
WHEN (id = 2) THEN (select DISTINCT name from tb_test where id = 1)
END )

[Err] 1093 - 您无法在 FROM 子句中指定要更新的目标表“tb_test”

最佳答案

这对你有用

  UPDATE tb_test
set name =
(
CASE
WHEN id = 1
THEN (select * from (select DISTINCT name from tb_test where id = 2)t)
WHEN id = 2
THEN (select * from (select DISTINCT name from tb_test where id = 1)y)
END
);

关于mysql - 我想交换数据用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35764083/

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