という名前のテーブルを想像してくださいGroup
。各グループは、下位の「レベル」である限り、「子」グループを持つことができます。したがって、テーブル間には一対多の関係がありGroup and childGroup
ます。
and の間にもmany-to-many
関係があるため、各テーブルの FK を保持するために使用されます。Group
Items
Groups_Items
、グループ、、given Group key
およびすべてのクエリを作成する必要があります。find all its child
all the childs of child groups
the customers belonging to those found groups
ある種の再帰クエリである必要があることはわかっていますが、SQL でこれを行う方法がわかりません。以下は、説明したテーブルの構造です。
したがって、上記の表にこれらのデータセットがある場合:
クエリは find でしたFor Group 1, find Its customers, Its Child groups (and their Childs) and all their customers
。出力は次のようになります。
<Group> 1
<customer> 1
<customer> 2
<Group> 2
<customer> 2
<Group> 3
<Group> 4
誰かがこれを行う方法を教えてもらえますか? ありがとう