• notice
  • Congratulations on the launch of the Sought Tech site

MySQL Gets the total number of rows of GroupBY

mysql gets the total number of group by records in a field, but the group cannot be calculated The number of records.

mysql's SQL_CALC_FOUND_ROWS uses the number of rows to get the query.It is written like this in many paging programs: p>

The code is as follows

SELECT COUNT(*) from `table` WHERE......;

Find the total number of records that meet the conditions

The code is as follows

SELECT * FROM `table` WHERE......limit M,N;

Query the data to be displayed on the page.Such a sentence can be changed to:

The code is as follows

SELECT SQL_CALC_FOUND_ROWS * FROM `table` WHERE......limit M, N;

SELECT FOUND_ROWS();

So it can be implemented with the SQL_CALC_FOUND_ROWS and FOUND_ROWS() functions that come with 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,20SELECT FOUND_ROWS() as count ;

Use the above two statements to complete the total number of records that meet the group by.

Attach:

The simple way to use group by:

The code is as follows

'SELECT column_id,count(*) as count FROM my_table group by column_id';

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+