查询某一字段的某一个值的总条数
比如:orderprogressno字段的值分别为1,2,3,4,那么就是查询值为1的总条数和值为2的总条数
已阅读 = sum(case when orderprogressno =1 then 1 else 0 end),
未阅读 = sum(case when orderprogressno =2 then 1 else 0 end),
from servicerepair
select orderno ,
sum(case when orderprogressno =1 then 1 else 0 end),as yiyuedu
sum(case when orderprogressno =1 then 1 else 0 end),as weiyuedu
from servicerepair group by orderno
mybatis下代码:
<select id="selectCountBylevel" parameterType="java.util.Map" resultType="java.util.Map">
select count (case when orderprogressno =1 then 1 else null end) 已阅读,
count (case when orderprogressno =2 then 1 else null end) 已联系,
count (case when orderprogressno =3 then 1 else null end) 已预约,
count (case when orderprogressno =4 then 1 else null end) 正在服务,
count (case when orderprogressno =5 then 1 else null end) 已经完成,
count (case when orderprogressno =6 then 1 else null end) 已经结束,
count (case when orderprogressno =7 then 1 else null end ) 已经取消
from servicerepair where deptno =#{deptno}
</select>