How does mysql obtain the total number of groupby records?

Source: Internet
Author: User
This article describes how mysql can obtain the total number of records of groupby. The specific method is analyzed as follows: In general, mysql obtains the total number of record groups for a field within the group by obtaining the groupby, but cannot count the number of records in the group. Mysql can use SQL _CALC_FOUND_ROWS to obtain the number of queried rows.

This article describes how mysql can obtain the total number of group by records. The detailed analysis method is as follows: Generally, mysql obtains the total number of record groups in a field when obtaining group by, but cannot count the number of records in the group. Mysql can use SQL _CALC_FOUND_ROWS to obtain the number of queried rows.

This article describes how mysql can obtain the total number of group by records. 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:

Select count (*) from 'table' WHERE ......;


Check the total number of qualified records:

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


To query the data to be displayed on the page, you can change the statement:

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:

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:

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

I hope this article will help you design MySQL database programs.

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.