按功能添加组值

时间:2016-11-10 15:20:56

标签: mysql

select 
  id
 ,rnwfees1
 ,count(cd.subscriberid) as cnt
 ,sum(revenue) as actalamt 
 ,TIMESTAMPDIFF(MONTH,commisiondate,now())+1 as cnt
 ,renewalfee*(TIMESTAMPDIFF(MONTH,commisiondate,now())+1) as expected 
From corporatesubscribers cs 
inner join po_location pl on pl.wo_no=cs.workorderid and pl.loc_code=cs.loc_code 
inner join special_plans sp on cs.packageid=sp.packageid 
inner join corporatedisbursement cd on cd.subscriberid=cs.cosubid 
where cs.workorderid='WOPO/0005/TN/0002' 
group by cd.id

id |rnwfees1 | cnt | actalamt | cnt   | expected |    
1  | 2199.00 | 14  | 30786.00 |    21 | 46179.00 |    
2  | 2199.00 | 14  | 30786.00 |    20 | 43980.00 |
3  | 2199.00 | 14  | 30786.00 |    20 | 43980.00 |    
4  | 2199.00 | 14  | 30786.00 |    22 | 48378.00 |    
5  | 2199.00 | 14  | 30786.00 |    21 | 46179.00 |    

我想要总和(actalamt)。我试过了。

1 个答案:

答案 0 :(得分:0)

我猜你正在寻找WITH ROLLUP修饰符。这是一个文档:enter image description here