MySQL nested set model, how to output parent from child perspective

Asked 2 months ago, Updated 2 months ago, 1 views

The MySQL nested set model is used to print "parent from child" but it doesn't work

Below is the table containing the category.

Table containing the category.

Below is a query that prints the parent from the child's perspective.

select node.rgt, concat(repeat(', count(parent.category_name)-1), node.category_name) as name, node.category_description
from category as node, category as parent 
where node.lft between parent.lft and 4
group by node.category_name order by node.lft;  

Below is the result of the query.

Enter a description of the image here

Looking at the execution results, I would like to display the execution results in three columns per line.
How do you think it will work?I look forward to your kind cooperation.

mysql

2022-09-30 12:09

2 Answers

Why don't you use GROUP_CONCAT?

select node.rgt, GROUP_CONCAT(node.category_name SEPARATOR'') as name...

You can use DISTINCT or ORDER BY inside GROUP_CONCAT.


2022-09-30 12:09

This is the hierarchical data of the nested model.

http://www.geocities.jp/mickindex/database/db_tree_ns.html
Wouldn't it work if you refer to 2-7. Enumerate Paths (Columned Version) on this site?


2022-09-30 12:09

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.