2015-09-29 35 views
1
CSU:       
    csuid,  csuname,   
    100   china    
    101   england  

    LOAN: 
    csuid, Arears empid 
    100  155 100 
    100  250 100 
    103  322 100 
    103  065 100 

什麼是csuname..i'm堅持這一GET和其他多部未華用於獲取命名

slect csuid as csu,sum(arears) as csu_total from loan where empid='100'group by csuid; 

這個作品獲得arears和組它的總和的最佳方式,我可以得到csuid,但我想爲此獲得csuname。

回答

0

嘗試:

select CSU.*, sum(loan.Arears) 
from CSU inner join loan on csu.csuid = loan.csuid 
group by csu.csuname 
0

這應有助於:

Select CSU.*, Sum (LOAN.arears) As totalArears FROM CSU Left Join LOAN On CSU.csuid = LOAN.csuid Group By (CSU.csuname)