gpt4 book ai didi

mysql - 如何从表列中删除空值?

转载 作者:行者123 更新时间:2023-11-29 02:55:11 38 4
gpt4 key购买 nike

我有一个数据库表,其中填充了 10k 行数据。这些行中有很多在特定列中具有空值。如何用例如字符串列的空字符串替换此空值?

我正在寻找执行此操作的最简单方法,因为此操作只需要执行一次

我尝试过的:

UPDATE tablename set mycolumn='' where mycolumn is null;

这给了我以下错误:

Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.

我不是数据库的管理员,所以我不能禁用安全模式。

UPDATE tablename set mycolumn=''
where Id in (SELECT Id FROM tablename where mycolumn is null);

这给了我以下错误:

Error Code: 1093. You can't specify target table 'tablename' for update in FROM clause.


注意:

在上面的示例中,我用占位符替换了真实的表名和列名。

最佳答案

你可以试试

UPDATE tablename set mycolumn = '' 
where Id IN (select Id from (select Id from tablename where mycolumn IS NULL) as x)

但是为什么要用空字符串替换 NULL 值呢?

如果您可以禁用安全模式 this将是重复的。

关于mysql - 如何从表列中删除空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31335384/

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