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

Instructions for the use of advanced grouping group by, group by cube, group by rollup

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

Share

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

1. Sum by job and deptno respectively

Select sum (sal), job,deptno from emp group by grouping sets (job,deptno)

2. 2 ^ n-1 grouping (n represents the number of columns, if there are multiple columns enclosed in parentheses to calculate a column, for example: cube ((aprimeb), c) naught 2transfercube (amemeb) naught 2

Select sum (sal), deptno,job from emp group by cube (deptno,job)

Cube__ > 2 ^ n

-- group by 0

-- group by job

-- group by deptno

-- group by deptno,job

3. Nasty 1 grouping

Select sum (sal), deptno,job from emp group by rollup (deptno,job)

Rullup-- > nasty 1

-- group by deptno,job

-- group by deptno

-- group by 0

4. Detect whether to participate in the grouping grouping ()

Select sum (sal), deptno,job,grouping (deptno), grouping (job) from emp group by cube (deptno,job)

The result set 1 of the query indicates that there is no participation in the grouping; 0 indicates the participation score

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