SQL挑战难题:如何使用SQL查询创建ASCII艺术层次树?

SQL挑战难题:如何使用SQL查询创建ASCII艺术层次树?,第1张

SQL挑战/难题:如何使用SQL查询创建ASCII艺术层次树? SQLiteVertical siblings
with        last_sibling (id) as (     select      max (id)     from        h     group by    pid ),tree (id,branch,path) as (     select      1       as id     ,''      as branch     ,'001'   as path     union all     select      h.id     ,t.branch || case when ls.id is not null then ' ' else '|' end || '    '     ,t.path || '_' || substr ('00000' || h.id,-5)     from         tree t      left join   last_sibling    ls      on          ls.id   =       t.id      join        h      on          h.pid =       t.id ),vertical_space (n) as (     select      1     union all     select      vs.n + 1     from        vertical_space  vs     where       vs.n < 2 )select      t.branch || case vs.n when 1 then '|____' || ' ' || cast (t.id as text) else '|' endfrom         tree t cross join  vertical_space  vsorder by    t.path,vs.n desc;


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5431666.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-11

发表评论

登录后才能评论

评论列表(0条)

    保存