【问题】
Let’s say I have given data as string:
+———-+
|Size |
+———-+
|15X10 |
|5X4 |
|3 |
|2X6X5 |
+———-+
I want to write this column as integer like this:
+———-+
|Size |
+———-+
|150 |
|20 |
|3 |
|60 |
+———-+
Some of them are multiply of three numbers, some of them just one number. I can split the string but cannot make MySQL to calculate the number. Thank you.
【回答】
对于任意的四则运算、带多重括号且多个操作数的运算,用 SQL 很难实现。可以在 SPL 中用动态结构化计算来解决,脚本如下:
| A | |
| 1 | $select * from tb |
| 2 | =A1.run(Size=eval(replace(Size,"X","*"))) |
A1:查询 tb 表

A2:将字符 X 替换为乘法符号 *,对字符串动态解析为表达式并计算

本文介绍如何使用MySQL处理包含乘法运算的字符串尺寸表示,如'15X10'转为150,通过动态计算解决复杂格式的数据转换问题。
686

被折叠的 条评论
为什么被折叠?



