MySql Modified preorder tree to create url

前端 未结 1 416
死守一世寂寞
死守一世寂寞 2021-01-23 05:24

This question is based on my previous question on stackoverflow. This time I am trying to generate urls for all the rows in pages table using the Modified Preorder Tree method.<

相关标签:
1条回答
  • 2021-01-23 06:24

    Something like this should suffice...

    SELECT CONCAT_WS('/',x.path,y.page_name) full_path
      FROM
         ( SELECT node.id, GROUP_CONCAT(parent.title ORDER BY parent.lft SEPARATOR '/') path
             FROM category node
             JOIN category parent
               ON node.lft BETWEEN parent.lft AND parent.rgt
            GROUP 
               BY node.title
            ORDER 
               BY node.lft
         ) x
      JOIN pages y
        ON y.category_id = x.id;
    
    0 讨论(0)
提交回复
热议问题