扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:赛迪网 韩劲草 来源:天新网 2008年3月22日
关键字: SQL SQL Server 数据库 Mssql
在本页阅读全文(共4页)
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.代码示例:
--------------------------------------
已连接。
SQL> set autot on
SQL> set timi on
SQL> select code 代码 , substrb(" ",1,item_level*2-2)||b.reg_type 登记注册类型, cnt 家数 from
2 (
3 (select substr(z01_08,1,1)||"00" code ,count(*) cnt
4 from cj601
5 group by substr(z01_08,1,1))
6 union
7 (select substr(z01_08,1,2)||"0" code ,count(*) cnt
8 from cj601
9 group by substr(z01_08,1,2))
10 union
11 (select substr(z01_08,1,3) code ,count(*) cnt
12 from cj601
13 group by substr(z01_08,1,3))
14 )
15 c, djzclx b where c.code=b.reg_code;
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。