Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为 net_amount 的列,它包含 244,98 之类的值。它是一个 varchar 列。当我尝试使用 sum 函数对其求和时,它仅对 244 求和并跳过小数位。我尝试将其转换为十进制,如下所示:
select cast(net_amount as decimal) from mytable
这也跳过了小数位......知道可能出了什么问题吗?
谢谢!
您可以使用 REPLACE 将逗号替换为点:
SELECT REPLACE('244,98', ',', '.') * 1
或者你可以像这样使用 CAST:
cast(REPLACE(net_amount, ',', '.') as decimal(8,2))