Expression nickname with SUM is not working

Asked

Viewed 97 times

3

I’m trying to make a SUM in a query that performs some calculations. Follow the example:

SELECT
 SUM ( (qtd - qtd_devolucao) * valor AS total)
FROM
 produtos
WHERE
 id_pedido = '47'

I’m having the following mistake:

#1064 - You have a syntax error in your SQL next to 'Total AS')

  • You want the sum to be called total?

  • I want to add all the total

  • And what is the expression that forms the total?

  • I want the total receives (qtd - qtd_devolucao) * valor Then I want to have a sum in the total.

1 answer

5


  • It didn’t work out, keep making the same mistake.

  • @Hugoborges put a Fiddle showing that it works, you must be doing it wrong, or the question is wrong.

  • Sorry, the mistake really was mine. It worked 100%, thank you.

Browser other questions tagged

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