【练手】cube和grouping的分组统计
来源:互联网 发布:淘宝运营规划方案 编辑:程序博客网 时间:2024/05/17 09:41
[code=SQL]
------------------------------------------------------------------------
-- author:jc_liumangtu(【DBA】小七)
-- date: 2010-03-05 17:00:41
-- version:
-- Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
-- Oct 14 2005 00:33:37
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
------------------------------------------------------------------------
use test
set nocount on
if object_id('test2','U') is not null
drop table test2
go
create table test2
(
area char(10),
[month] char(10),
total_sale int
)
insert into test2
select '广州','1月',2000 union all
select '广州','2月',2500 union all
select '深圳','1月',1000 union all
select '深圳','2月',2000
go
select * from test2
select (case when grouping(area)=1 and grouping([month])=1 then '所有地区'
when grouping(area)=1 and grouping([month])=0 then '月份小记' else area end) area
,isnull([month],'总计') [month],sum(total_sale) as [sum(total_sale)] from test2 group by area,[month] with cube
area month total_sale
---------- ---------- -----------
广州 1月 2000
广州 2月 2500
深圳 1月 1000
深圳 2月 2000
area month sum(total_sale)
---------- ---------- ---------------
广州 1月 2000
广州 2月 2500
广州 总计 4500
深圳 1月 1000
深圳 2月 2000
深圳 总计 3000
所有地区 总计 7500
月份小记 1月 3000
月份小记 2月 4500
[/code]
- 【练手】cube和grouping的分组统计
- sql 的cube rollup 和grouping
- ROLLUP和CUBE语句。 ORACLE分组统计
- ROLLUP和CUBE语句。 ORACLE分组统计
- 高级分组实例【rollup,cube,grouping sets】
- 高级分组ROLLUP,CUBE,GROUPING,GROUPING SETS操作
- Oracle分组函数 rollup、cube、grouping sets、grouping、grouping_id
- oracle 显示多个分组的统计结果 GROUPING SETS
- ROLLUP、CUBE 和GROUPING用法 .
- group、grouping、rollup、cube的用法和区别
- group、grouping、rollup、cube的用法和区别
- oracle分组汇总统计函数grouping
- Oracle数据分组:group by,having,rollup,cube,grouping sets
- oracle 11g:高级分组:rollup,cube,grouping sets
- Jarno详解Oracle高级分组函数(ROLLUP, CUBE, GROUPING SETS)
- hive grouping sets 和 cube 用法
- Postgresql GROUPING SETS、CUBE和ROLLUP
- oracle rollup cube grouping grouping sets(转载收藏的)
- 『分享』各种提示、输入对话框的使用
- 条款26:尽可能延后变量定义式的出现时间
- Developer Express一些小技巧
- C# 实现的多线程异步Socket数据包接收器框架(来源http://www.cnblogs.com/wcfgroup/archive/2008/10/06/1304512.html)
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- 【练手】cube和grouping的分组统计
- STL测试
- 解密淘宝网的开源架构
- insert into 和insert into select性能比较
- sql 实现记录有重复只显示一条。
- 通过轮询数据源数据行状态更新数据库
- 关于stream的初步认识
- Linux软件安装及卸载
- Visual C++/MFC入门教程(一)