SQL One statement statistic record total and each state number _mssql

Source: Internet
Author: User

Method One,

Copy Code code as follows:

SELECT sum (the correct number) +sum (Error number) as total record number, sum (correct number), sum (Number of errors)
From (
SELECT count (1) correct number, 0 error number
From TB
WHERE Status=1
UNION All
SELECT 0 Correct number, COUNT (1) Error
From TB
WHERE status=0) A

Method Two,

Copy Code code as follows:
Select COUNT (1) Total records, sum (case when Status=1 then 1 else 0-end) correct number, sum (case when status=0 then 1 else 0-end) error number from T

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.