gpt4 book ai didi

mysql - 在mysql数据库的两列中拆分浮点值

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

我在这种格式的“VARCHAR”类型的一列中错误地输入了 2 个值value1.value2(浮点值格式)例如 5.10、4.0、3.11 等

现在我想将这两个值拆分为两个单独的列,类型为“INT”我已经创建了列,我只需要一个查询。

我不知道如何编写查询来拆分一列的值并更新其他列。有知道的帮忙看看。

谢谢

最佳答案

这在 MySQL 中很容易做到:

select cast(substring_index(varcharcol, '.', 1) as unsigned) as val1,
cast(substring_index(varcharcol, '.', -1) as unsigned) as val2

编辑:

如果你愿意,你也可以在 update 中这样做:

update table t
set val1 = cast(substring_index(varcharcol, '.', 1) as unsigned),
val2 = cast(substring_index(varcharcol, '.', -1) as unsigned)

关于mysql - 在mysql数据库的两列中拆分浮点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22445910/

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