Calculation in query in the Database

Asked

Viewed 47 times

1

Guys I have a certain problem if I make an appointment in the comic book, the SELECT makes a calculation of some columns in the database and generates a new field with the name lucro but if there is number with comma he ignores the comma and does not show in this new generated field, if someone gives me a light how to make him calculate the comma together I thank

code of consultation:

 SELECT ID_Pacote,produto.Nome, 
 peca,FK_ID_Produto,Quantidade,Data_entrada,Data_saida 
 ,CONCAT(ROUND(pacote.Quantidade * produto.Preco  ), ' R$ ') 
 AS 'Lucro'  FROM Pacote INNER JOIN Produto on pacote.FK_ID_Produto = 
 produto.ID_Produto

1 answer

1


In your SQL, the use of ROUND is incorrect, it is rounding without decimal.

Use in this way:

ROUND(pacote.Quantidade * produto.Preco, 2) -- o 2 significa 2 casas decimais :)

In case your SQL would be:

SELECT ID_Pacote,produto.Nome, 
 peca,FK_ID_Produto,Quantidade,Data_entrada,Data_saida 
 ,CONCAT(ROUND(pacote.Quantidade * produto.Preco, 2  ), ' R$ ') 
 AS 'Lucro'  FROM Pacote INNER JOIN Produto on pacote.FK_ID_Produto = 
 produto.ID_Produto

More information on how to use, visit this link

I hope I’ve helped! :)

  • It worked, thanks, I learned to do it the wrong way, thanks for the tip

  • Opa, that’s great... Don’t forget to mark as the correct answer, because other people can go through the same problem and already find the solution.. :)

  • Marco yes, only need to wait 5 min to mark sksk

  • face me a doubt, I wanted to put the R$ before the value, any suggestions ?

  • 1

    Uses Concat(), type CONCAT('R$ ', '10,00'); Likes: https://www.w3schools.com/sql/func_mysql_concat.asp

  • 1

    Valeu Man :)...

Show 1 more comment

Browser other questions tagged

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