oracle cube和rollup

本文介绍了SQL中的ROLLUP和CUBE聚合函数的使用方法,并通过具体示例展示了如何使用这两个函数进行数据分组统计,包括不同分组列组合的统计结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

功能介绍:

首先是进行无字段的聚合,然后依次对每个字段进行聚合

创建表:

 View Code

插入测试数据:

 View Code

ROLLUP:

Select t.classid,t.studentname,Sum(t.score) From Score t Group By Rollup(t.classid,t.studentname); 

查询结果:

Cube:

Select t.classid,t.studentname,Sum(t.score) From Score t Group By Cube(t.classid,t.studentname); 

查询结果:

相对于collup,多个如图的8行记录:

Rollup(t.classid,t.studentname):统计的分组列包括()、(classid)和(classid,studentname)

Cube(t.classid,t.studentname):统计的分组列包括()、(classid)、(studentname)和(classid,studentname)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值