dongzhong7299 2014-05-18 14:26
浏览 26
已采纳

嵌套设置如何确定左右节点

 1 - Root - 20

 2 - child1 - 3
 4 - child2 - 5
 6 - child3 - 7
 8 - child4 - 9

This is a nested set model of mysql.

let's say that the _lft and _rgt are the fields which indicates the left and right values

as I see the lower the value is the lefter are the child? so here we got 2 childs from the left side, and 2 childs from the right side, can be this done without adding a new field like direction which may indicate the child direction before inserting it?

I want to determine this only using _lft and _rgt, I can't figure out what is the logic, even in words, no code nessesary

How can I make a query only those childs who belongs to the left side relative to the parent?

any suggestions please, thanks.

  • 写回答

1条回答 默认 最新

  • douzepao0281 2014-05-18 14:48
    关注

    I think you really need to work on understanding how the nested set works.

    I would read this for the diagram of the model and how new nodes are inserted (the rest is good info, too). http://falsinsoft.blogspot.com/2013/01/tree-in-sql-database-nested-set-model.html

    Note that all leaves are _rgt = _lft + 1. The _lft of the left most leaf is min(select _lft .... where _rgt = _lft + 1).

    Combine this knowledge with the path to a node query on that same page and I think you'll have what you need.

    An additional resource is the wikipedia page:

    http://en.wikipedia.org/wiki/Nested_set_model

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号