Group by返回第一个值而不是分组

时间:2016-08-03 20:59:17

标签: sql group-by

SELECT userid, 
    Round((totalhold - playercomps - freemoney - (depositmade_amt*.1)),2) as SpecValue, txndate

FROM player_activity

WHERE userid = 2026939

GROUP BY month(txndate)

理想情况下,我会计算每个月此用户的价值。但是,我的查询只返回每个月的第一个值。例如,如果June有3个SpecValues(10,20,30),我的查询只返回第一个SpecValue(10)。

帮助?

1 个答案:

答案 0 :(得分:0)

SELECT userid, 
    Sum(Round((totalhold - playercomps - freemoney - (depositmade_amt*.1)),2)) as SpecValue, txndate

FROM player_activity

WHERE userid = 2026939

GROUP BY month(txndate)