分类汇总(复杂一点)
来源:互联网 发布:数据库 集群 编辑:程序博客网 时间:2024/05/30 04:42
1.按照科目分组做小计,客户分组做总计 id-科目,company-客户
客户包含多个科目
e.g:
select * from (select * from (select mater.ob as ob,mater.id as id,mater.num as num,mater.company as company
from
(select id||company as ob,id,num,company from (
select 'a' id ,10 as num,'A' as company
union all
select 'a' id ,20 as num,'A' as company
union all
select 'b' id ,30 as num,'A' as company
union all
select 'b' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
))mater
union all
select * from (select * from (select (id||company||'_') ob,null as id,sum(num) as num,company from (
select 'a' id ,10 as num,'A' as company
union all
select 'a' id ,20 as num,'A' as company
union all
select 'b' id ,30 as num,'A' as company
union all
select 'b' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
) group by company,id) order by company) order by ob) groupby
union all
select * from (select null as ob,company as id,sum(res.num) as num,company||'_' as company from (
select (id||company||'_') ob,id,sum(num) as num,company from (
select 'a' id ,10 as num,'A' as company
union all
select 'a' id ,20 as num,'A' as company
union all
select 'b' id ,30 as num,'A' as company
union all
select 'b' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
union all
select 'c' id ,40 as num,'B' as company
) group by company,id) res group by res.company) aa) order by company,ob
效果:
aA a 20 A
aA a 10 A
aA_ 30 A
bA b 30 A
bA_ 30 A
A 60 A_
bB b 40 B
bB_ 40 B
cB c 40 B
cB c 40 B
cB_ 80 B
B 120 B_
-----上帝啊,,,头都大了...
- 分类汇总(复杂一点)
- 复杂一点的变换
- 复杂一点的CV
- 分类汇总
- 分类汇总
- 复杂Struts Validation汇总
- 一个复杂一点的例子
- 一个复杂一点的变化
- 复杂选择器分类总结图
- Excel分类汇总
- 分类汇总GROUPING
- 数据检索-分类汇总
- SQL分类汇总
- 一个分类汇总
- SQL分类汇总
- 一条sql 分类汇总
- 小学英语单词分类汇总
- Linux常用命令分类汇总
- 常用工具汇总-备忘
- PowerShell学习笔记[分享]
- 持久数据层框架设计(二)
- 作诗一首
- 微软Office Live Workspace最近的一些新Features
- 分类汇总(复杂一点)
- 蜘蛛爬虫网络高像素图片抓取工具[搜索引擎]
- 使用Win7后感
- 看世间,论成败,人生只不过是要豪迈
- libdca解码器32位定点化
- 服务层框架设计(二)——服务请求示例
- 服务层框架设计(一)——简要介绍
- 海纳百川 有容乃大, 壁立千仞 无欲则刚
- svn备忘