用户登录
用户注册

分享至

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)

生成的结果图为
软件
前端设计
程序设计
Java相关