SQL 实现某时间段的统计业务
- 作者: 奥特激光biu_biu_biu
- 来源: 51数据库
- 2021-10-19
有一张错误上报表,下面只将与本文相关的字段罗列如下:上报人(reportperson)、上报错误id(errorid)、上报时间(reporttime)、状态(state),其中值为0(未解决)、1(已处理)、2(已解决)。
现在要做的是统计在某个时间段[begintime,endtime](其中begintime,endtime由前台进行传入)内,每个上报人上报错误点的总数以及已解决错误的总数。
select a.reportperson,a.sumoferror,b.solvederror
from(select count(errorid) as sumoferror,reportperson
from pcr_constructinfo
where
(reporttime>begintime) and (reporttime<endtime) group by reportperson)
a left join
(select reportperson,count(errorid) as solvederror
from pcr_constructinfo
where (state=2) and (reporttime>begintime) and (reporttime<endtime) group by reportperson) b
on (a.reportperson=b.reportperson)
生成的结果图为:
现在要做的是统计在某个时间段[begintime,endtime](其中begintime,endtime由前台进行传入)内,每个上报人上报错误点的总数以及已解决错误的总数。
复制代码 代码如下:
select a.reportperson,a.sumoferror,b.solvederror
from(select count(errorid) as sumoferror,reportperson
from pcr_constructinfo
where
(reporttime>begintime) and (reporttime<endtime) group by reportperson)
a left join
(select reportperson,count(errorid) as solvederror
from pcr_constructinfo
where (state=2) and (reporttime>begintime) and (reporttime<endtime) group by reportperson) b
on (a.reportperson=b.reportperson)
生成的结果图为:
推荐阅读
- SQLite数据库操作:原生操作,GreenDao操作讲解
- 数据库SQL实战题:获取员工其当前的薪水比其manager当前薪水还高的相关信息(教程)
- SQLSERVER查询区分大小写的写法分析
- SQL学习总结之SQL的分类介绍
- 阶梯到高级T-SQL 1级:高级T-SQL介绍交叉连接
- 高级T-SQL级别1的Stairway:使用CROSS JOIN引入高级T-SQL分析
- 什么是SQL隔离级别?四个SQL隔离级别定义介绍
- Sql递归介绍之用with实现递归查询
- SQLSERVER查询时日期格式化的实例讲解
- 数据库SQL实战:从titles表获取按照title进行分组,注意对于重复的emp_no进行忽略(题解)
热点文章
SQLite数据库操作:原生操作,GreenDao操作讲解
18
数据库SQL实战题:获取员工其当前的薪水比其manager当前薪水还高的相关信息(教程)
4
SQLSERVER查询区分大小写的写法分析
36
SQL学习总结之SQL的分类介绍
6
阶梯到高级T-SQL 1级:高级T-SQL介绍交叉连接
4
高级T-SQL级别1的Stairway:使用CROSS JOIN引入高级T-SQL分析
4
什么是SQL隔离级别?四个SQL隔离级别定义介绍
2
Sql递归介绍之用with实现递归查询
6
SQLSERVER查询时日期格式化的实例讲解
4
数据库SQL实战:从titles表获取按照title进行分组,注意对于重复的emp_no进行忽略(题解)
7