Reputation: 31
I got 2 tables and I want list the result of each day from salesman.
One table contain salesman info ( id,name)
The other contain the sales of the day (saleschipcell, cell)
After joining two tables, I got the result from each day:
salesman John, day -> 01/03/2012 cell -> 15, chip cell ->30
salesman Bob, day -> 01/03/2012 cell -> 5, chip cell ->10
salesman John, day -> 01/04/2012 cell -> 10, chip cell ->0
salesman Bob, day -> 01/04/2012 cell -> 10, chip cell ->2
Ok.Is there a possibility to get the total of sales from cell and chipcell from John and BOB like this:
Total of the day , day -> 01/03/2012 cell -> 20, chip cell ->40
Total of the day , day -> 01/04/2012 cell -> 20, chip cell ->2
I tried with SUM
, but generates only one result, but SUM get all from all salesman.
Upvotes: 1
Views: 280
Reputation: 3996
If you want it by day and by person use two columns in Group by
SELECT `day`,`salesman_id`,SUM('cell') as cell, SUM(`chipcell`) as chipcell
FROM `sales`
GROUP BY `day`, `salesman_id`
ORDER BY `day`
Upvotes: 0
Reputation: 4601
SELECT `day`,SUM('cell'), SUM(`chipcell`) FROM `sales` GROUP BY `day`;
Upvotes: 0
Reputation: 34837
You can group the results per salesman to get the totals for that specific person. Example:
SELECT `day`, SUM(`saleschipcell`) FROM `sales` GROUP BY `salesman_id`;
Should give you the amount of sales per day per salesman.
Upvotes: 3