This article describes how to obtain the total number of records of groupby by mysql. This function is implemented through the groupbySQL_CALC_FOUND_ROWS statement, which has some practical value, for more information about how to obtain the total number of group by records from mysql, see the following example. The specific method is analyzed as follows:
In general, mysql can obtain the total number of record groups for a field within the group by, but cannot count the number of records in the group.
In mysql, you can use SQL _CALC_FOUND_ROWS to obtain the number of queried rows, which is written in many paging programs as follows:
The code is as follows:
Select count (*) from 'table' WHERE ......;
Check the total number of qualified records:
The code is as follows:
SELECT * FROM 'table' WHERE... limit M, N;
To query the data to be displayed on the page, you can change the statement:
The code is as follows:
SELECT SQL _CALC_FOUND_ROWS * FROM 'table' WHERE... limit M, N;
SELECT FOUND_ROWS ();
Therefore, the following functions can be used with the SQL _CALC_FOUND_ROWS and FOUND_ROWS () functions provided by mysql:
The code is as follows:
SELECT SQL _CALC_FOUND_ROWS t3.id, a, bunch, of, other, stuff FROM t1, t2, t3 WHERE (associate t1, t2, and t3 with each other) GROUPBY t3.id LIMIT 10, 20 SELECT FOUND_ROWS () as count;
Use the preceding two statements to complete the total number of records that meet the requirements of group.
Supplement:
Simple use of group:
The code is as follows:
'Select column_id, count (*) as count FROM my_table group by column_id ';
I hope this article will help you design MySQL database programs.