mysql json将字符串替换为整数

时间:2017-12-12 08:19:24

标签: mysql json

如何将JSON中的所有值从字符串替换为整数?

+-----------------------------------+ 
| video_related                     |
+-----------------------------------+ 
| ["8626416", "8457156", "8605962"] |
+-----------------------------------+

Change to:
+-----------------------------------+ 
| video_related                     |
+-----------------------------------+ 
| [8626416, 8457156, 8605962]       |
+-----------------------------------+

2 个答案:

答案 0 :(得分:0)

您可以使用 CONVERT

SELECT stuff
FROM table
WHERE conditions
ORDER BY CONVERT(name_column, SIGNED INTEGER);

答案 1 :(得分:0)

您也可以使用CAST:

SELECT CAST(col AS SIGNED INTEGER)
FROM table