Adding data from a column

4
  

id .. product ... value ... sales_id ... total value

     

01 .. Pen .... 2.00 .... 1 .......... 30.00

     

02 .. Rubber. 4.00 .... 2 ........... 25.50

     

03..Lapis ...... 5.00 .... 1 ........... 10.00

     

04 .. Pointer 9.00 ... 1 ........... 200.00

Well considering this table, I would need to sum all the values of the column valortotal but only those that have id_venda equal to 1 how would I do it?

ex: SALES_ID 1 TOTAL VALUE 240.00.

    
asked by anonymous 05.01.2016 / 19:07

1 answer

9

Use the SUM () command that sums the values in a column:

SELECT
  SUM('valortotal') as 'Valor Total'
FROM
  produtos
WHERE
  id_venda = 1;

See working here : link

    
05.01.2016 / 19:22