<legend id='wTDf3'><style id='wTDf3'><dir id='wTDf3'><q id='wTDf3'></q></dir></style></legend>
    <bdo id='wTDf3'></bdo><ul id='wTDf3'></ul>

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

      1. <tfoot id='wTDf3'></tfoot>
        <i id='wTDf3'><tr id='wTDf3'><dt id='wTDf3'><q id='wTDf3'><span id='wTDf3'><b id='wTDf3'><form id='wTDf3'><ins id='wTDf3'></ins><ul id='wTDf3'></ul><sub id='wTDf3'></sub></form><legend id='wTDf3'></legend><bdo id='wTDf3'><pre id='wTDf3'><center id='wTDf3'></center></pre></bdo></b><th id='wTDf3'></th></span></q></dt></tr></i><div id='wTDf3'><tfoot id='wTDf3'></tfoot><dl id='wTDf3'><fieldset id='wTDf3'></fieldset></dl></div>
      2. sqlite3 上的基本递归查询?

        时间:2023-10-10
      3. <legend id='WsTZI'><style id='WsTZI'><dir id='WsTZI'><q id='WsTZI'></q></dir></style></legend>
            • <bdo id='WsTZI'></bdo><ul id='WsTZI'></ul>

            • <small id='WsTZI'></small><noframes id='WsTZI'>

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

                  <tfoot id='WsTZI'></tfoot>
                    <tbody id='WsTZI'></tbody>
                  本文介绍了sqlite3 上的基本递归查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个简单的 sqlite3 表,如下所示:

                  表:部分零件超零件wk0Z wk00wk06 wk02wk07 wk02eZ01 eZ00eZ02 eZ00eZ03 eZ01eZ04 eZ01

                  我需要运行递归查询来查找给定 SuperPart 及其所有子部件的所有对.假设我有 eZ00.eZ00 是 eZ01 的超部分,eZ01 是 eZ03 的超部分.结果不仅必须包括对 (eZ00, eZ01) 和 (eZ01 和 eZ03),还必须包括对 (eZ00, eZ03).

                  我知道还有其他定义表格的方法,但我在这里别无选择.我知道如果我知道我的树的深度,我可以使用多个联合,但我并不总是知道我想要多深.使用 WITH RECURSIVE 或什至只是 WITH (,,) AS x 之类的东西会有所帮助,但是对于我搜索过的内容,这在 sqlite 中是不可能的,对吧?

                  有没有办法在 sqlite3 中进行这种递归查询?

                  更新:

                  提出这个问题时,SQLite 不支持递归查询,但是 让我们知道这次 SQLite 更新.

                  <小时>

                  3.8.3 之前的版本中,SQLite 不支持递归 CTE(或根本不支持 CTE),因此没有 在 SQLite 中使用.由于您不知道它的深度,因此您无法使用标准的 JOIN 技巧来伪造递归 CTE.您必须以艰难的方式做到这一点,并在您的客户端代码中实现递归:

                  • 获取初始行和子部分 ID.
                  • 获取子部件的行和子部件 ID.
                  • 重复直到没有任何反应.

                  I have a simple sqlite3 table that looks like this:

                  Table: Part
                  Part    SuperPart
                  wk0Z    wk00
                  wk06    wk02
                  wk07    wk02
                  eZ01    eZ00
                  eZ02    eZ00
                  eZ03    eZ01
                  eZ04    eZ01
                  

                  I need to run a recursive query to find all the pairs of a given SuperPart with all of its subParts. So let's say that I have eZ00. eZ00 is a superpart of eZ01 and eZ01 is a superpart of eZ03. The result must include not only the pairs (eZ00, eZ01) and (eZ01 and eZ03) but must also include the pair (eZ00, eZ03).

                  I know there are other ways of defining the table, but I have no choice here. I know i can use several unions if I know the depth of my tree, but I won't allways know how depth I want to go. It'd help to have something like WITH RECURSIVE or even just WITH (,,) AS x but for what I've searched, that's not possible in sqlite, right?

                  Is there a way to do this recursive query in sqlite3?

                  UPDATE:

                  When this question was made, SQLite didn't support recursive queries, but as stated by @lunicon, SQLite now supports recursive CTE since 3.8.3 sqlite.org/lang_with.html

                  解决方案

                  If you're lucky enough to be using SQLite 3.8.3 or higher then you do have access to recursive and non-recursive CTEs using WITH:

                  Thanks to lunicon for letting us know about this SQLite update.


                  In versions prior to 3.8.3, SQLite didn't support recursive CTEs (or CTEs at all for that matter) so there was no WITH in SQLite. Since you don't know how deep it goes, you can't use the standard JOIN trick to fake the recursive CTE. You have to do it the hard way and implement the recursion in your client code:

                  • Grab the initial row and the sub-part IDs.
                  • Grab the rows and sub-part IDs for the sub-parts.
                  • Repeat until nothing comes back.

                  这篇关于sqlite3 上的基本递归查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Chrome 中的加密 cookie 下一篇:如何在电子中使用 sqlite3 模块?

                  相关文章

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

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

                  • <bdo id='uZQP9'></bdo><ul id='uZQP9'></ul>

                    <legend id='uZQP9'><style id='uZQP9'><dir id='uZQP9'><q id='uZQP9'></q></dir></style></legend><tfoot id='uZQP9'></tfoot>