oracle dba 常用语句10(group by)
2013-01-07 10:40
465 查看
########################## 增强的 group by 子句 ######################### select [column,] group_function(column)... from table [WHERE condition] [GROUP BY [ROLLUP] group_by_expression] [H***ING having_expression]; [ORDER BY column]; -------ROLLUP 操作字,对 group by 子句的各字段从右到左进行再聚合 example: /* 其结果看起来象对 col1 做小计 */ select col1,col2,sum(col3) from table group by rollup(col1,col2); /* 复合 rollup 表达式 */ select col1,col2,sum(col3) from table group by rollup((col1,col2)); select [column,] group_function(column)... from table [WHERE condition] [GROUP BY [CUBE] group_by_expression] [H***ING having_expression]; [ORDER BY column]; -------CUBE 操作字,除完成 ROLLUP 的功能外,再对 ROLLUP 后的结果集从右到左再聚合 example: /* 其结果看起来象对 col1 做小计后,再对 col2 做小计,最后算总计 */ select col1,col2,sum(col3) from table group by cube(col1,col2); /* 复合 rollup 表达式 */ select col1,col2,sum(col3) from table group by cube((col1,col2)); /* 混合 rollup,cube 表达式 */ select col1,col2,col3,sum(col4) from table group by col1,rollup(col2),cube(col3); /*GROUPING(expr) 函数,查看 select 语句种以何字段聚合,其取值为 0 或 1*/ select [column,] group_function(column)...,GROUPING(expr) from table [WHERE condition] [GROUP BY [ROLLUP] group_by_expression] [H***ING having_expression]; [ORDER BY column]; example: select col1,col2,sum(col3),grouping(col1),grouping(col2) from table group by cube(col1,col2); /*grouping sets 操作,对 group by 结果集先对 col1 求和,再对 col2 求和,最后将其结果集并在一起 */ select col1,col2,sum(col3) from table group by grouping sets((col1),(col2));
相关文章推荐
- ORACLE DBA 常用语句1
- oracle DBA常用sql语句二
- oracle dba常用语句5
- oracle DBA常用的sql语句
- oracle DBA常用操作语句 持续更新。。。
- oracle DBA常用语句
- oracle DBA常用语句
- ORACLE DBA 常用语句
- oracle常用语句之新建表空间、新建用户、给用户DBA权限及windows 导入dmp文件
- oracle dba常用语句6
- oracle dba 常用语句2
- Oracle DBA常用语句第1/2页
- oracle dba 常用语句7(password,role,user)
- oracle dba常用语句3
- oracle dba 常用语句8(basic sql)
- ORACLE深入 第一章ORACLE DBA常用语句和脚本(1)
- oracle dba 常用语句9(table,view,sequence)
- SqlServer和Oracle中一些常用的sql语句10 特殊应用
- SqlServer和Oracle中一些常用的sql语句10 特殊应用
- Oracle 常用DBA语句 日常DBA维护的SQL命令收集