inuff inuff -4 years ago 87
SQL Question

SQL Sum returns a false value

I have an issue with the SUM-Function in my MySQL Workbench. When I use the function, it returns a false value.
I´d like to SUM these three numbers:


  • 56,03

  • 35,59

  • 54,35



The result should be 145,97, but its just 145 instead. I tried these different codes:

SELECT SUM(price) FROM table;


This one returns the value 145.

SELECT ROUND(SUM(price),2) FROM table;


The second one returns the value 145.00.

I was wondering whats wrong with the code, because I tried it in another DB that I have in my MySQL Workbench. Also tried it over the Terminal in both databases. In the other database the function works correctly.

Answer Source

Best thing to do would be to change your table so that it is a decimal field.

However, if you can't do that, the following query should get what you want:

SELECT SUM(replace(price,',', '.')) FROM tbl;

You can test in on SQLFiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download