SQL Type subtype Statistics

Source: Internet
Author: User
Tags csb1

SELECT * from TestTable;

Type subtype Value

A SA 1
Bsb1
Asberror
Bsaerror
Asb1
Bsb1
Csaerror
Csb1
Csc1
Csc1
Csaerror


Select sum (' value ') from testtable where value! = ' ERROR ' and type = ' B ';


SUM (' value ')

2


SELECT Type,subtype,sum (value) as Totnum from testtable WHERE value! = ' ERROR ' GROUP by Type,subtype;

Type subtype Totnum

A SA 1
Asb1
Bsb2
Csb1
Csc2
Csc2


SELECT Type,subtype,count (value) as Totcount from testtable WHERE value = ' ERROR ' GROUP by Type,subtype;

Type subtype Totcount

A SB 1
Bsa1
Csa2
Csa2


SELECT * FROM (case when value <> ' ERROR ' then value Else ' 0 ' end) as total, sum (case when Valu E = ' ERROR ' then 1 Else ' 0 ' end ' as Error line ' from TestTable Group by Type,subtype ' t ORDER by total desc

Type subtype total number of error rows

C SC 2 0
Bsb20
Asa10
Csb10
Asb11
Csa02
Bsa01

SQL Type subtype Statistics

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.