1.多级 cte 查询示例。

with cte as
(
   select pageid 
   from cm_bookpage
) , cte2 as
(
  select pageid, 2 as content from cte
)
select * from cte2

2. cte 递归查询文章标题层级,3872某一叶子节点,要查询出所有上级目录并排序返回。

with cte as
(
  select pageid,bookid,title,parentpageid,1 as orderid
  from cm_bookpage 
  where pageid = 3872        
  union all  
  select a.pageid,a.bookid,a.title,a.parentpageid,(cte.orderid+1) as orderid
  from cm_bookpage a  
    inner join cte       
      on a.pageid = cte.parentpageid  
)
select *
from cte
order by orderid desc 

 

相关文章:

  • 2021-07-06
  • 2021-07-22
  • 2022-03-05
  • 2022-12-23
  • 2021-09-22
  • 2021-08-23
  • 2021-06-12
  • 2022-12-23
猜你喜欢
  • 2021-06-19
  • 2021-12-29
  • 2022-12-23
  • 2021-08-31
  • 2021-08-01
相关资源
相似解决方案