欢迎来到福编程网,本站提供各种互联网专业知识!
您的位置:网站首页 > 数据库 > MsSql

SQL 实现某时间段的统计业务

发布时间:2013-01-17 作者: 来源:转载
有一张错误上报表,现在要做的是统计在某个时间段[beginTime,endTime](其中beginTime,endTime由前台进行传入)内,每个上报人上报错误点的总数以及已解决错误的总数,闲话不说,看代码
有一张错误上报表,下面只将与本文相关的字段罗列如下:上报人(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 (ReportTimea left join
(select ReportPerson,COUNT(ErrorID) as solvedError
from PCR_ConstructInfo
where (State=2) and (ReportTime>beginTime) and (ReportTimeon (a.ReportPerson=b.ReportPerson)

生成的结果图为

相关推荐