ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 数据库 >> DB2 >> DB2两个递归集合合并

DB2两个递归集合合并

来源:网络整理     时间:2017-05-02     关键词:

本篇文章主要介绍了" DB2两个递归集合合并",主要涉及到方面的内容,对于DB2感兴趣的同学可以参考一下: 一般用with可以连接两个集合,但是递归有所不同,通常我们会改写成如下的错误代码: with report(id,org_name,org_level,pa...

一般用with可以连接两个集合,但是递归有所不同,通常我们会改写成如下的错误代码:
with
report(id,org_name,org_level,parent_org,description)
as (select id,org_name,org_level,parent_org,description from ad_orgtb where id = '111111'
union all select b.id,b.org_name,b.org_level,b.parent_org,b.description from report a,ad_orgtb b where b.id = a.parent_org
)
, reportOne(id,org_name,org_level,parent_org,description)
as (select id,org_name,org_level,parent_org,description from ad_orgtb where id = '111111'
union all select bb.id,bb.org_name,bb.org_level,bb.parent_org,bb.description from reportOne aa,ad_orgtb bb where bb.parent_org = aa.id
)
select distinct id,org_name,org_level,parent_org,description from report,reportOne

正确的写法应该如下:

with report(id,org_name,org_level,parent_org,description)
as (select id,org_name,org_level,parent_org,description from ad_orgtb where  id = '22222'unionallselect b.id,b.org_name,b.org_level,b.parent_org,b.description from report a,ad_orgtb b where  b.id = a.parent_org) 
,report_result(id,org_name,org_level,parent_org,description) 
as (
    selectdistinct id,org_name,org_level,parent_org,description from report orderby org_level,id
)
,reportOne(id,org_name,org_level,parent_org,description) 
as (
    select id,org_name,org_level,parent_org,description from ad_orgtb where  id = '222222'unionallselect b.id,b.org_name,b.org_level,b.parent_org,b.description from reportOne a,ad_orgtb b where  b.parent_org = a.id
) 
,reportOne_result(id,org_name,org_level,parent_org,description) as (
    selectdistinct id,org_name,org_level,parent_org,description from reportOne orderby org_level,id
)selectdistinct * from (
SELECT id,org_name,org_level,parent_org,description
from report_result
unionallselect id,org_name,org_level,parent_org,description
from reportOne)t

要先将结果集取了,才能放置多个递归。

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了 DB2两个递归集合合并,包括了方面的内容,希望对DB2有兴趣的朋友有所帮助。

    本文网址链接:http://www.codes51.com/article/detail_4298161.html

  • 相关图片

    相关文章