I have a table with three columns in which one of the columns has the customer_id (columnA), in the second the orders placed (columnB) and in the last the date of the order (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 would need to get the total orders of each client in a range of dates
(2018-02-01/2018-02-28)
columnaA columnaB(sum_total)
1 41
2 4
3 50
I've tried this query but it only outputs 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
use this have statement if it works for you
It should be something like this since it shows the total of columnB :
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: columnC 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 you will have problems.