微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

有一张错误上报表,下面只将与本文相关的字段罗列如下:上报人(ReportPerson)、上报错误ID(ErrorID)、上报时间(ReportTime)、状态(State),其中值为0(未解决)、1(已处理)、2(已解决)。 现在要做的是统计在某个时间段[beginTime,endTime](其中beginTime,endTime由前台进行传入)内,每个上报人上报错误点的总数以及已解决错误的总数。
<div class="codetitle"><a style="CURSOR: pointer" data="16207" class="copybut" id="copybut16207" onclick="doCopy('code16207')"> 代码如下:

<div class="codebody" id="code16207">
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)

生成的结果图为


<IMG src="https:https://files.jb51.cc/file_images/article/201301/2013117110840560.png?201301711919"&gt;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐