mysql 复杂sql的处理

1.需要汇总同一用户的资金,还要根据这些资金的类型进行分类统计:

使用案例:

select cms.uid,sum(cms.money) 总支出,sum(case when cms.change_type='7' then cms.money else 0 end) as 激活用户,
sum(case when cms.change_type='5' then cms.money else 0 end) as 转账,
sum(case when cms.change_type<>'5' and cms.change_type<>'7' then cms.money else 0 end) as 其他
from cms_member_funds cms where cms.money<0 GROUP BY cms.uid

参考网站:http://www.jb51.net/article/46205.htm

posted @ 2016-11-21 21:53  Aaronqcd  阅读(239)  评论(0编辑  收藏  举报