Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query to sum decimal numbers

I am trying to sum my decimal records e.g.

There is a column in my table named cash having values like 40.33, 30.00, 77.22. How can I create a query that sum up these records? I am trying hard using SUM(cash) and ROUND(SUM(cash),2) but no result.

SELECT cash FROM `enrolled 

return rows.

SELECT ROUND(SUM(cash),2)`

return 0 row.

like image 257
Muhammad Imran Tariq Avatar asked Oct 07 '11 02:10

Muhammad Imran Tariq


1 Answers

try this.

SELECT ROUND(SUM(cash), 2)
FROM <tablename>

If you are getting no results, then there must be a null value, try this instead.

SELECT ROUND(SUM(cash), 2)
FROM<tablename> a
WHERE cash IS NOT NULL

Tell me if there is anything else to help you with.

like image 181
Nathan Avatar answered Oct 05 '22 23:10

Nathan