SQL statement and field quantity when the database calculates the number of different fields

Source: Internet
Author: User

SQL statement and field quantity when the database calculates the number of different fields

Today, fields in Table A are queried, and different types of fields are collected;


1. select count (1) from A where strwhere collects statistics on the number of qualified rows

2. select count (filed) from A where strwhere collects statistics on the number of rows in the qualified columns, basically the same as above

The following are the highlights of today

3. when the field type is 0, 1, it is the simplest, but is commonly used for example: 1. male and female; 2. yes, no; When 0, 1 can be used as the positive and negative type of the type;

Select sum (filde1), sum (filde2) from A where strwhere

When multiple fields are queried and of a fixed type (typeA, typeB ....)

4. select sum (case when filed1 = typeA1 then 1 else 0 end), sum (case when filed2 = typeA2 then 1 else 0 end) from A where strwhere

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.