mysql Queries with arithmetic operations

-1

I have tried to find some kind of query that does arithmetic operations to show them in a table only the result. I've tried with count() but I only get the data and not the operations, such as adding and multiplying the sales.

For example, from sale 1 I have 3 different items get the summation and if I had more than 1 unit also multiplication, some subject that I recommend read to do so? so far I only achieve it by going through the vector that returns the query and doing the operations with php functions,

The query is normal:

SELECT * Fecha FROM 'ventas';

What is not done is how to make the summation of all the data. When I apply count and sum I only return the value of for example, sale 1 and not all sales.

The query that only returns my sales number but not the sum of the items sold, is where I'm stuck

SELECT NoVenta, COUNT(*) FROM ventas GROUP by NoVenta

<table>
  <tr>
    <th>No. Venta</th>
    <th>Total</th>
  </tr>
  <tr>
    <td>1</td>
    <td>550</td>
  </tr>
  <tr>
    <td>2</td>
    <td>700</td>
  </tr>
  <tr>
    <td>3</td>
    <td>800</td>
  </tr>
  <tr>
    <td>4</td>
    <td>900</td>
  </tr>
  <tr>
    <td>5</td>
    <td>600</td>
  </tr>
  <tr>
    <td>6</td>
    <td>500</td>
  </tr>
</table>
    
asked by huichochitlan 02.01.2019 в 04:23
source

1 answer

1

Your error is in using the count () function, it only counts the elements. What you need is the sum () function that adds up.

select NoVenta, sum(PVenta) as total from ventas group by NoVenta

The sum is made with the field PVenta, just change the field for which you need and ready.

    
answered by 02.01.2019 / 05:35
source