sql 统计查询某一字段的某一个值的总条数

查询某一字段的某一个值的总条数

比如:orderprogressno字段的值分别为1,2,3,4,那么就是查询值为1的总条数和值为2的总条数

select orderno,count(orderprogressno)from servicerepair
已阅读  = 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>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值