What are the statements used for grouping in mysql?

下次还敢
Release: 2024-04-27 06:15:20
Original
777 people have browsed it

MySQL grouping statement MySQL provides the following statements for grouping data: 1. GROUP BY: Group rows by grouping key; 2. HAVING: Filter grouping results; 3. WITH ROLLUP: Create summary rows; 4. WITH CUBE: Create multidimensional summary rows.

What are the statements used for grouping in mysql?

Group Statements in MySQL

The following statements are available in MySQL to group data:

GROUP BY

The GROUP BY statement groups together rows with the same grouping key value. The grouping key can be a single column or a combination of multiple columns.

<code class="sql">SELECT column_list
FROM table_name
GROUP BY grouping_column_list;</code>
Copy after login

HAVING

The HAVING statement is used to filter grouped results. It is used with the GROUP BY statement to apply conditions on grouped data sets.

<code class="sql">SELECT column_list
FROM table_name
GROUP BY grouping_column_list
HAVING condition;</code>
Copy after login

WITH ROLLUP

WITH ROLLUP statement is used to create summary rows in a GROUP BY operation. It adds summary rows for each grouping level to the result set.

<code class="sql">SELECT column_list
FROM table_name
GROUP BY grouping_column_list WITH ROLLUP;</code>
Copy after login

WITH CUBE

The WITH CUBE statement is used to create multidimensional summary rows in a GROUP BY operation. It adds summary rows for all possible subset groupings to the result set.

<code class="sql">SELECT column_list
FROM table_name
GROUP BY grouping_column_list WITH CUBE;</code>
Copy after login

The above is the detailed content of What are the statements used for grouping in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!