Add different values MySql

0

I have a table with three columns in which one of the columns has the client_id (columnA), in the second the orders made (columnB) and in the last one the order date (columnC)

columnaA    columnaB    columnaC

   1           26      2018-02-09
   1           15      2018-02-10
   2           4       2018-02-09
   3           32      2018-02-09
   3           18      2018-02-10

I need to get the total of orders from each client in a range of dates
 (2018-02-01 / 2018-02-28)

columnaA    columnaB(sum_total)

   1           41
   2           4
   3           50

I have tried this query but it only takes me one record:

SELECT distinct columnaA, sum(columnaB) as total FROM tabla.pedidos
where columnaC BETWEEN '2018-02-01' AND '2018-02-28';

columnaA    columnaB(total)

    1           95
    
asked by hayber 28.02.2018 в 15:53
source

3 answers

0

use this sentence if it serves you

SELECT SUM(columnaB) AS total FROM tu_nombre_bd 
WHERE columnaC BETWEEN '2018-02-01' AND '2018-02-28'
GROUP BY columnaA;
    
answered by 28.02.2018 / 15:59
source
0

SELECT columnaA as NIT_CLIENTE ,SUM(columnaB) AS TOTAL_PEDIDOS FROM tabla.pedidos WHERE columnaC BETWEEN '2018-02-01' AND '2018-02-28' GROUP BY columnaA

keep in mind the following: Column C will search for you correctly because it is in year month day and is of type string, if you have it in another date format that string will have problems.

    
answered by 28.02.2018 в 16:10
0

It should be something like this since it shows the total of the columnB :

SELECT columnaA, sum(columnaB) as total FROM tabla.pedidos
where columnaC BETWEEN '2018-02-01' AND '2018-02-28'
Group by columnaA
    
answered by 28.02.2018 в 16:02