mysql语句中的sum(if(exp1,exp2,exp3))

http://blog.csdn.net/wuhuagu_wuhuaguo/article/details/78367735函数

 

MYSQL 手册中MYSQL 函数 if() 的使用
if(expr1,expr2,expr3) 
若是 expr1 是TRUE ,则if()的返回值为expr2; 不然返回值则为 expr3。if() 的返回值为数字值或字符串值,具体状况视其所在语境而定。.net

  1. select sum(if(money > 0, money, 0)) as total_money   from product group by id;  

这句是累加全部商品价格大于0元的金额获得总金额blog

相关文章
相关标签/搜索