Mysql gets a method for group by total record rows _mysql

Source: Internet
Author: User

This article describes the MySQL to get group by total record row number of methods, share for everyone for reference. The specific methods are analyzed as follows:

In general, MySQL gets the total number of records grouped by the group by internally that can get to a field, and cannot count the number of records grouped.

In MySQL, you can use Sql_calc_found_rows to get the number of rows in a query, which is written in many paging programs:

Copy Code code as follows:
SELECT COUNT (*) from ' table ' WHERE ...;

Identify the total number of eligible records:
Copy Code code as follows:
SELECT * from ' table ' WHERE ... limit m,n;

Query the data to be displayed by the page such that a statement can be changed to:
Copy Code code as follows:
SELECT sql_calc_found_rows * from ' table ' WHERE ... limit M, N;
SELECT found_rows ();

So the Sql_calc_found_rows and found_rows () functions that can be combined with MySQL can be implemented:
Copy Code code as follows:
SELECT sql_calc_found_rows t3.id, a,bunch,of,other,stuff from T1, T2, T3 where (associate, T1,t2,and, and each other) T3 Upby t3.id LIMIT 10,20select found_rows () as Count;

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

Add:

Simple use of GROUP by:

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

I hope this article is helpful to the design of MySQL database.

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.