zoukankan      html  css  js  c++  java
  • SQL 实现统计业务

    有一张错误上报表,下面只将与本文相关的字段罗列如下:上报人(ReportPerson)、上报错误ID(ErrorID)、上报时间(ReportTime)、状态(State),其中值为0(未解决)、1(已处理)、2(已解决)。

    现在要做的是统计在某个时间段[beginTime,endTime](其中beginTime,endTime由前台进行传入)内,每个上报人上报错误点的总数以及已解决错误的总数。

    1 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)

    生成的结果图为:

  • 相关阅读:
    杂题
    jzoj5679
    CF434E
    jzoj6152
    jzoj6150
    mysql 第06章 运算符
    mysql 第05章 数据类型
    mysql 第04章 SQL语句
    mysql 第03章 体系结构
    mysql 第02章 基本操作
  • 原文地址:https://www.cnblogs.com/junfly/p/2859658.html
Copyright © 2011-2022 走看看