Phsyco_Developer Phsyco_Developer - 16 days ago 5
MySQL Question

Mysql sum of row values depending of the other same field

I need to Sum of Cash and Credit of each company with Corresponding date

+-----------+------------+---------------+--------+----------
| ID | SaleDate | Cash | Credit |company |
+-----------+------------+---------------+--------+----------
| 1 | Nov-12-2016| 100 | 150|company 1|
| 2 | Nov-12-2016| 200 | 100|Company 1|
| 3 | Nov-13-2016| 150 | 200|Company 2|
| 4 | Nov-13-2016| 250 | 250|Company 2|
| 5 | Nov-14-2016| 80 | 50|Company 3|
| 6 | Nov-14-2016| 500 | 600|Company 3|
| | Nov-15-2016| 300 | 300|Company 4|
+-----------+------------+---------------+--------+---------+


Desired OutPut is

+------------+---------------+--------+----------
| SaleDate | Cash | Credit |company |
+------------+---------------+--------+----------
| Nov-12-2016| 300 | 250|company 1|
| Nov-13-2016| 400 | 450|Company 2|
| Nov-14-2016| 580 | 650|Company 3|
| Nov-15-2016| 300 | 300|Company 4|
+-----------+------------+---------------+------+


i don' know how to do this please help me to find a solution thanks in advance...

Answer
select  SaleDate,sum(Cash)Cash,sum(Credit)Credit,company   
from tbl_name group by  
SaleDate,company 
Comments