MySQL SUM()函数按条件求和(转)
原文:https://blog.csdn.net/fu_fei_wen/article/details/78646410
- 一般求和
select sum(money) from user group by id;
- 按条件求和
select sum(if(type=1,money,0)) from user group by id;
原文:https://blog.csdn.net/fu_fei_wen/article/details/78646410
select sum(money) from user group by id;
select sum(if(type=1,money,0)) from user group by id;