oracle:sql之with as 使用

设计描述:使用ztree显示树结构,此树中线路(单表)、标段(复杂筛选,查询结果也需要union)、资料名称属于不同表,单位类型需要与查询条件一致,并且在每个单位类型下都要将资料列表罗列出来(罗列的资料列表是相同的),如此一来就需要多表的union然后再start with tt.parentId = 'root'
connect by prior tt.id = tt.parentId  连接成树。

oracle:sql之with as 使用

       框架中使用mybatis,使用with as 将线路、标段、单位类型和资料定义成四张临时表:

       with lineTb as(select * from 线路表),

              sectionTb as (select * from 筛选出的标段表),

              unitTypeTb as (),

              catalogTb as ()

       select id,name,parentId

from(

  select * from lineTb union select * from sectionTb union  select * from unitTypeTb  union  select * from catalogTb

)tt   start with tt.parentId = 'root'
      connect by prior tt.id = tt.parentId