2016-11-10 59 views
0
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 

通過fucntion增加一個值組

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)。我嘗試過這個。請幫助它解決問題

+0

對不起,我需要總和(預期) –

+1

請仔細閱讀[**如何對向**](http://stackoverflow.com/help/how-to-ask) \t \t這裏是[** START **]的好地方(http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)瞭解如何提高您的問題質量並獲得更好的答案。 –

回答