2017-02-10 68 views
-1
 SELECT tbl_trans.trans_username, 
    Sum(Case When tbl_trans.trans_type <> 'REWARD' AND tbl_trans.trans_winlose <> 'QB' then 
     trans_winloseamount Else 0 End) BETHOST, 
    Sum(Case When tbl_trans.trans_winlose = 'QB' then 
     trans_winloseamount Else 0 End) QB, 
    Sum(Case When tbl_trans.trans_type = 'REWARD' then 
     trans_winloseamount Else 0 End) reward , 
     Sum(sum(BETHOST)+sum(QB)+sum(reward)) totalsum 
FROM tbl_trans 
GROUP BY trans_username 

我需要totalsum BETHOST,QB和獎勵
如何總結這Sum(sum(BETHOST)+sum(QB)+sum(reward)) totalsumMySQL的總和之列

+0

在相同的結果,上述查詢或一個彙總行? – GurV

+0

@GurV在相同的結果,相同的查詢 –

+0

請參閱http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-是-A-極簡單的SQL查詢 – Strawberry

回答

0

PLS的嘗試這個

sum(SELECT(BETHOST))+sum(SELECT(QB))+sum(SELECT(reward)) AS totalsum