Home >Daily Programming >Mysql Knowledge >What are the statements used for grouping in mysql?

What are the statements used for grouping in mysql?

下次还敢
下次还敢Original
2024-04-27 06:15:20857browse

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>

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>

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>

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>

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!

Statement:
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