1.sum(if)
代码语言:javascript复制select
sum(if(status=1,1,0)) as s1_count,
sum(if(status=2,1,0)) as s2_count
from order;
2.count()
代码语言:javascript复制select
count(status=1 or null) as s1_count,
count(status=2 or null) as s2_count
from order;
注意:count是返回匹配条件的行数,只要有值就会算进去,所以这里不符合条件的算作Null
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100282.html原文链接: