• <tfoot id='DgScI'></tfoot>

  • <i id='DgScI'><tr id='DgScI'><dt id='DgScI'><q id='DgScI'><span id='DgScI'><b id='DgScI'><form id='DgScI'><ins id='DgScI'></ins><ul id='DgScI'></ul><sub id='DgScI'></sub></form><legend id='DgScI'></legend><bdo id='DgScI'><pre id='DgScI'><center id='DgScI'></center></pre></bdo></b><th id='DgScI'></th></span></q></dt></tr></i><div id='DgScI'><tfoot id='DgScI'></tfoot><dl id='DgScI'><fieldset id='DgScI'></fieldset></dl></div>
      1. <small id='DgScI'></small><noframes id='DgScI'>

      2. <legend id='DgScI'><style id='DgScI'><dir id='DgScI'><q id='DgScI'></q></dir></style></legend>
          <bdo id='DgScI'></bdo><ul id='DgScI'></ul>

        如何递归查找孩子的所有ID?

        How to find all IDs of children recursively?(如何递归查找孩子的所有ID?)

        <legend id='4kBBX'><style id='4kBBX'><dir id='4kBBX'><q id='4kBBX'></q></dir></style></legend>

      3. <i id='4kBBX'><tr id='4kBBX'><dt id='4kBBX'><q id='4kBBX'><span id='4kBBX'><b id='4kBBX'><form id='4kBBX'><ins id='4kBBX'></ins><ul id='4kBBX'></ul><sub id='4kBBX'></sub></form><legend id='4kBBX'></legend><bdo id='4kBBX'><pre id='4kBBX'><center id='4kBBX'></center></pre></bdo></b><th id='4kBBX'></th></span></q></dt></tr></i><div id='4kBBX'><tfoot id='4kBBX'></tfoot><dl id='4kBBX'><fieldset id='4kBBX'></fieldset></dl></div>

        • <tfoot id='4kBBX'></tfoot>

              • <bdo id='4kBBX'></bdo><ul id='4kBBX'></ul>

                  <small id='4kBBX'></small><noframes id='4kBBX'>

                    <tbody id='4kBBX'></tbody>
                  本文介绍了如何递归查找孩子的所有ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想仅使用 MySQL 获取树中子项的所有 ID.

                  I would like to get all IDs from children in a tree with MySQL only.

                  我有一张这样的桌子:

                  ID parent_id name
                  1  0         cat1
                  2  1         subcat1
                  3  2         sub-subcat1
                  4  2         sub-subcat2
                  5  0         cat2
                  

                  现在我正在尝试递归获取 cat1 (2,3,4) 的所有子 ID.有什么方法可以实现吗?

                  Now I'm trying to get all child IDs for cat1 (2,3,4) recursively. Is there any way how to achieve that?

                  推荐答案

                  有两种基本方法可以做到这一点:邻接列表和嵌套列表.看看在 MySQL 中管理分层数据.

                  There are two basic methods for doing this: adjacency lists and nested lists. Take a look at Managing Hierarchical Data in MySQL.

                  你拥有的是一个邻接表.不,没有一种方法可以使用单个 SQL 语句递归地获取所有后代.如果可能,只需将它们全部抓取并在代码中全部映射.

                  What you have is an adjacency list. No there isn't a way of recursively grabbing all descendants with a single SQL statement. If possible, just grab them all and map them all in code.

                  嵌套集可以做你想做的事,但我倾向于避免它,因为插入记录的成本很高,而且容易出错.

                  Nested sets can do what you want but I tend to avoid it because the cost of inserting a record is high and it's error-prone.

                  这篇关于如何递归查找孩子的所有ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                  1. <legend id='BTJ8J'><style id='BTJ8J'><dir id='BTJ8J'><q id='BTJ8J'></q></dir></style></legend><tfoot id='BTJ8J'></tfoot>

                        <small id='BTJ8J'></small><noframes id='BTJ8J'>

                          <tbody id='BTJ8J'></tbody>
                        <i id='BTJ8J'><tr id='BTJ8J'><dt id='BTJ8J'><q id='BTJ8J'><span id='BTJ8J'><b id='BTJ8J'><form id='BTJ8J'><ins id='BTJ8J'></ins><ul id='BTJ8J'></ul><sub id='BTJ8J'></sub></form><legend id='BTJ8J'></legend><bdo id='BTJ8J'><pre id='BTJ8J'><center id='BTJ8J'></center></pre></bdo></b><th id='BTJ8J'></th></span></q></dt></tr></i><div id='BTJ8J'><tfoot id='BTJ8J'></tfoot><dl id='BTJ8J'><fieldset id='BTJ8J'></fieldset></dl></div>
                        • <bdo id='BTJ8J'></bdo><ul id='BTJ8J'></ul>