Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

GROUPING & GROUPING_ID & GROUP_ID & GROUPING SETS

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Grouping ()

The function must accept one column and can only accept one column as its argument. The parameter column value returns 1 if the parameter column value is empty, and 0 if the parameter column value is not empty.

Second, grouping_id () function

GROUPING_ID can receive multiple columns, return values in parameter order, use the grouping () function for each parameter in turn, and then string the resulting values into a string of binary numbers and then convert them into decimal values.

For example: grouping (A) = 0; grouping (B) = 1

Then: grouping_id (A _ maeb) = (01) = 1

Grouping_id (BBME A) = (10) = 2

Example:

SELECT DIVISION_ID

JOB_ID

GROUPING (DIVISION_ID) AS DIV_GRP

GROUPING (JOB_ID) AS JOB_GRP

GROUPING_ID (DIVISION_ID, JOB_ID) AS GRP_ID

SUM (SALARY) FROM EMPLOYEES2

GROUP BY CUBE (DIVISION_ID, JOB_ID)

ORDER BY DIVISION_ID, JOB_ID; III, GROUP_ID () function

The GROUP_ID function can be used to eliminate duplicate records returned by the GROUP BY clause. GROUP_ID () does not accept any parameters. If a particular packet is repeated n times, GROUP_ID () returns an integer from 0 to NMMI 1.

Example:

SELECT DIVISION_ID, JOB_ID, GROUP_ID (), SUM (SALARY)

FROM EMPLOYEES

GROUP BY DIVISION_ID, ROLLUP (DIVISION_ID, JOB_ID); IV. GROUPING SETS

Grouping sets is equivalent to combining the grouping conditions of multiple group by, and the empty grouping condition is the sum of all the data.

Example:

SELECT GROUPING_ID (S.PRODUCT, S.COUNTRY)

GROUPING (PRODUCT)

GROUPING (COUNTRY)

PRODUCT

COUNTRY

SUM (SALES)

FROM PLCH_SALES S

GROUP BY GROUPING SETS ((S.PRODUCT), (S.COUNTRY), ())

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report