如下sql,为计算用户收益总和:
<select id="getTotalIncome" resultType="com.lws.test.modules.user.entity.UserIncomeEntity">
select sum(income) as totalIncome
from income_log
where uid = #{uid,jdbcType=BIGINT}
</select>
其中返回的求和字段类型需要设置为 BigDecimal:
public class UserIncomeEntity {
private BigDecimal totalIncome;
}