SQL implements statistical services for a certain period of time

Source: Internet
Author: User

In an error report, only the fields related to this Article are listed as follows: ReportPerson, ErrorID, and ReportTime) status, where the values are 0 (not resolved), 1 (processed), and 2 (resolved ).

What we need to do now is to count the total number of error points reported by each reporter and the total number of resolved errors in a certain period of time [beginTime, endTime] (where beginTime and endTime are transmitted by the front-end.
Copy codeThe Code is as follows:
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)

The generated result graph is:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.