2016-07-04 342 views
0

好吧,让我先看看我的表格。总计按月分组的多列

我的专栏:

Outlet | tanggal | cash | cc | dc | flash | piutang | reject | disc50 

我所做的是和per day。我的查询到目前为止

select 
    Outlet, tanggal, 
    (cash + cc + dc + flash + piutang + reject + disc50) total 
from 
    transaksi 
where 
    outlet = 'K-AEON' 

该查询返回结果如下:

Outlet tanggal  total 
--------------------------- 
K-AEON 2016-01-22 2343300 
K-AEON 2016-01-23 6091200 
K-AEON 2016-01-24 6244700 
K-AEON 2016-01-26 3284100 
K-AEON 2016-01-25 1904600 
K-AEON 2016-01-27 2743500 

我要的是结果从上面group bymonth(tanggal)

到目前为止,我已经试过这

select 
    Outlet, month(tanggal), 
    (cash + cc + dc + flash + piutang + reject + disc50) total 
from 
    transaksi 
where 
    outlet = 'K-AEON' 
group by 
    month(tanggal), Outlet, cash, cc, dc, flash, piutang, reject, disc50 

,结果

Outlet month total 
---------------------- 
K-AEON 1 811100 
K-AEON 1 1220850 
K-AEON 1 1169700 
K-AEON 1 1147500 
K-AEON 1 1290000 

我期望的结果是

Outlet month total 
---------------------------------------- 
K-AEON 1 10000000 // all of January 
K-AEON 2 20000000 // All feb 
K-AEON 3 30000000 // All march 
K-AEON 4 40000000 // All April 
K-AEON 5 50000000 // All may 

任何帮助吗?对不起,我的英文不好

回答

3

你接近,但你需要使用sum,然后排除从group by这些领域:

select Outlet, month(tanggal), 
     sum(cash + cc + dc + flash + piutang + reject + disc50) total 
from transaksi 
where outlet = 'K-AEON' 
group by Outlet, month(tanggal)