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