Add decimal values in Mysql

Asked

Viewed 82 times

0

I have the following query:

SELECT SUM('ValorTotal') AS Pagos,StatusCadastros FROM pe_cadastros WHERE StatusCadastros = 'A';

On the field ValorTotal, who’s with the guy Decimal(7,2) has 02 values:

1500.00 and 570.00

Only that even having values, the result is returning me zero. I honestly do not know where is the problem in query.

Already includes the GROUP BY ValorTotal, but it still didn’t work.

2 answers

3


You’re trying to add a string no?

Total value would be a field, so the correct query would be:

SELECT SUM(ValorTotal) as Pagos, StatusCadastros from pe_cadastros WHERE StatusCadastros = 'A';
  • What a lack of attention from me. Forgive me for this!!

  • I was going to close this topic, but I’ll leave it open so that other unaware colleagues, as well as myself, can have a solution. Thank you all!

2

Column names should be written directly, not in quotes, so you’re having a text add up, which doesn’t make any sense. Then the right thing would be:

SELECT SUM(ValorTotal) AS Pagos, StatusCadastros FROM pe_cadastros WHERE StatusCadastros = 'A';

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.