首页|资讯|互联网|电信|硬件|软件|情报|产经|博客|家庭|商用电脑|游戏|评测|学院|下载|网络通信|方案应用|搜索
移动计算|商用软件|外包|开源|中间件|企业|IT经理|发烧友|程序员|IT女性|学生|老板|笔记本|手机|台式机|数码|论坛
程序员

详细介绍分级汇总实现的3种方法的比较

2008-03-19 23:56 作者:韩劲草 来源:赛迪网
[摘要] 详细介绍分级汇总实现的3种方法的比较含代码示例。
[关键字] 分级汇总 3种方法
  分级汇总实现的3种方法比较

  1.代码示例:

  --------------------------------------------------------

  select code 代码 , substrb(' ',1,item_level*2-2)  b.reg_type 登记注册类型, cnt 家数 from

  (

  (select substr(z01_08,1,1)  '00' code ,count(*) cnt

  from cj601

  group by substr(z01_08,1,1))

  union

  (select substr(z01_08,1,2)  '0' code ,count(*) cnt

  from cj601

  group by substr(z01_08,1,2))

  union

  (select substr(z01_08,1,3) code ,count(*) cnt

  from cj601

  group by substr(z01_08,1,3))

  )

  c, djzclx b where c.code=b.reg_code;

  代码 登记注册类型 家数

  ------ --------------------------------------- ---------

  100 内资企业

  110 国有企业

  120 集体企业

  130 股份合作企业

  140 联营企业

  141 国有联营企业

  142 集体联营企业

  143 国有与集体联营企业

  149 其他联营企业

  150 有限责任公司

  151 国有独资公司

  159 其他有限责任公司

  160 股份有限公司

  170 私营企业

  171 私营独资企业

  172 私营合伙企业

  173 私营有限责任公司

  174 私营股份有限公司

  200 港、澳、台商投资企业

  210 合资经营企业(港或澳、台资)

  220 合作经营企业(港或澳、台资)

  230 港、澳、台商独资经营企业

  240 港、澳、台商投资股份有限公司

  300 外商投资企业

  310 中外合资经营企业

  320 中外合作经营企业

  330 外资企业

  340 外商投资股份有限公司

  ----

  lastwinner

  type: substr(z01_08,1,1)  '00'

  subtype : substr(z01_08,1,2)  '0'

  sub-subtype : substr(z01_08,1,3)

  select ..........

  group by rollup(type, subtype, sub-subtype)

  大家可以试试看。

  2.代码示例:

  -----------------------------------------------------

  select code 代码 , substrb(' ',1,item_level*2-2)  b.reg_type 登记注册类型, cnt 家数 from

  (

  select

  case when code3 is not null then code3

  when code2<>'0' then code2

  else code1

  end code,cnt

  from (

  select substr(z01_08,1,1)  '00' code1 , substr(z01_08,1,2)  '0' code2 , substr(z01_08,1,3) code3 ,count(*) cnt

  from j601

  group by rollup(substr(z01_08,1,1),substr(z01_08,1,2),substr(z01_08,1,3))

  ) where code2<>code3 or code3 is null and code1<>'00'

  )

  c, djzclx b where c.code=b.reg_code

  order by 1

  ;

  最终版14.89秒

  代码:------------------------------------------

  select code 代码 , substrb(' ',1,item_level*2-2)  b.reg_type 登记注册类型, cnt 家数 from

  (

  select

  case when code3 is not null then code3

  when code2<>'0' then code2

  else code1

  end code,cnt

  from (

  select substr(z01_08,1,1)  '00' code1 , substr(z01_08,1,2)  '0' code2 , substr(z01_08,1,3) code3 ,sum(cnt) cnt

  from (select substr(z01_08,1,3) z01_08,count(*) cnt from j601 group by substr(z01_08,1,3))

  group by rollup(substr(z01_08,1,1),substr(z01_08,1,2),substr(z01_08,1,3))

  ) where code2<>code3 or code3 is null and code1<>'00'

  )

  c, djzclx b where c.code=b.reg_code

  order by 1

  ;

  在小一些的数据量上的执行情况:
关键词: 分级汇总, 3种方法,
  • 我要留言
关于eNet | 广告服务 | 版权声明 | 加入eNet | 联系我们 | 建议/投诉 | 网站导航 | 加入收藏

网站合作、内容监督、商务咨询、投诉建议:010-65245588
合作建议:hezuo@mail.enet.com.cn
Copyright © 1998--2008 硅谷动力公司版权所有 京ICP证000044号

京ICP证000044号