SQL: Recursive Path

前端 未结 5 850
北海茫月
北海茫月 2021-02-10 23:57

Is it possible to create a \"tree resolver\" in SQL?

I have a table:

ID Name Parent
1  a
2  b    1
3  c    1
4  d    3

Now I want a SQL

5条回答
  •  别那么骄傲
    2021-02-11 00:45

    Depending on what database server use, this functionality may be provided for you already. Otherwise you can create a function that call itself to return this information, or implement a Materialized Path solution.

    Update:

    For DB2 you can make use of Recursive Common Table Expressions.

提交回复
热议问题