gpt4 book ai didi

mysql - 将mysql中的值从column1复制到column2

转载 作者:行者123 更新时间:2023-11-29 07:37:12 26 4
gpt4 key购买 nike

我有一个名为 table1 的表,其中包含 column1(pk) 和 column2。

在sql中插入table1时,是否可以检查column2的值,如果column2的值为null,则将column1的值插入到columns2中

如果是这样我该怎么做?

最佳答案

是的,使用 IF 语句:

UPDATE table1
SET column2 = IF(column1 IS NOT NULL, column1, 'Something else')

关于mysql - 将mysql中的值从column1复制到column2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352216/

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