mysql行转列

来源:互联网 发布:数据库迁移解决方案 编辑:程序博客网 时间:2024/06/06 13:23

基本原理就是靠聚合以及case when 或者if,例子如下


select name,sum(case when stype=4 then money*(-1) else money end ) as M 
from table 
group by name 



select name,sum(money*IF(stype=4,-1,1)) as M 
from table 
group by name 

原创粉丝点击