How can I retrieve the total number of records of each column in one query?

Source: Internet
Author: User
Can I retrieve the total number of records in each column in one query? MySQL has a field: class_idclass_id11222533 ...... How to query each column at a time (or efficiently) to obtain the total number of records of each column. That is, there are 2 records with the class_id of 1, 3 records with the class_id of 2, 1 records with the class_id of 5, and 2 records with the class_id of 3 ,......, Can PHPcodeCreateTa retrieve the total number of records in each column at a time?
A MySQL table has a field: class_id.

Class_id
1
1
2
2
2
5
3
3
......

How to query each column at a time (or efficiently) to obtain the total number of records of each column. That is:
There are 2 records with a class_id of 1, 3 records with 2, 1 record with 5, and 2 records with 3 ,......



------ Solution --------------------
PHP code
Create TableCREATE TABLE 'demo' ('demoid' int (11) not null AUTO_INCREMENT, 'class _ id' int (11) default null, primary key ('demoid ')) ENGINE = MyISAM AUTO_INCREMENT = 8 default charset = utf8 // 2 input test data // 3 query select count (class_id), class_id FROM demo group by class_id

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.