格式
以;with cte开头 (定义哪些列)as (查询的顶层 union all 内链接CTE查询 循环)
以下是 sunlike ERP系统的BOM表递归查询实例
;with cte(hb,partno,bb,level,itm)
as
(
select bom_no,prd_no,id_no,0 as level,itm from tf_bom where bom_no=‘301-74100-01->’
union all
select tf_bom.bom_no,prd_no,tf_bom.id_no,cte.level+1 as level,tf_bom.itm from tf_bom inner join cte on tf_bom.bom_no=cte.bb
)
select * from cte