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.
我有一个表,其中有一列 :balance_amount类型VARCHAR
balance_amount
VARCHAR
现在我想SUM时遇到了问题。
示例:
如果我有内容栏:
125,000.00 170,000.00
它只会显示:295
295
我想要的是:295,000.00
295,000.00
您将需要删除千位分隔符。
select sum(replace(column,',','')) from table;
理想情况下,您应该使用适当的字段定义来存储数字,并且只是格式化数字以供显示。
这是SQLFiddle
SELECT FORMAT(SUM(CAST(REPLACE(REPLACE(col,',00',''),'.','') AS SIGNED)), 2) AS sumOfColumn FROM tab