MySQL gets the total number of record rows method for GROUP by

Source: Internet
Author: User

MySQL gets the group by interior can get the total number of record grouping statistics for a field, and cannot count the number of records grouped.


The number of rows that MySQL sql_calc_found_rows uses to get queries is written in many paging programs:

Code to copy code as follows

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

Find out the total number of records that match the criteria

Code to copy code as follows
SELECT * from ' table ' WHERE ... limit m,n;


A statement that queries the data to be displayed on a page can be changed to:

Code to copy code as follows
SELECT sql_calc_found_rows * from ' table ' WHERE ... limit M, N;

SELECT found_rows ();

Because (www.111cn.net) this can be implemented with MySQL's own sql_calc_found_rows and Found_rows () functions.

Code to copy code 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 all other) GRO Upby t3.id LIMIT 10,20select found_rows () as Count;


Use the above two statements to complete the total number of record rows that satisfy group by.

Also attached:

A simple way to use GROUP by:

Code to copy code as follows
' SELECT column_id,count (*) as Count from My_table Group by column_id ';

From:http://www.111cn.net/database/mysql/50323.htm

MySQL gets the total number of record rows method for GROUP by

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.