basic recursive query on sqlite3?

后端 未结 5 1930
猫巷女王i
猫巷女王i 2020-11-27 16:49

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    eZ         


        
5条回答
  •  再見小時候
    2020-11-27 17:33

    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:

    enter image description here

    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.

提交回复
热议问题