我有表名爲TabShop - 的cols和數據的一個子集是: (假設以掩蓋實際...)遞歸CTE和種子
|ShopCategory |Item |ItemOrCategory
|------------ |------------ |--------------
|Greens |Cabbage |item
|Greens |Cucumber |item
|Reds |Beetroot |item
|Reds |Onions |item
|Browns |Potatoes |item
|RootVeg |Browns |category
|Grocery |Greens |category
|Grocery |RootVeg |category
|Grocery |Rice |item
|RootVeg |Parsnip |item
|Vegetables |Reds |category
使用遞歸CTE,我需要如下顯示所有項目遍歷後...:
Category |Item
---------- |-----
Vegetables |Beetroot
Vegetables |Onions
Grocery |Rice
Grocery |Parsnip
Grocery |Cabbage
Grocery |Cucumber
Reds |Beetroot
Reds |Onions
Greens |Cabbage
Greens |Cucumber
RootVeg |Parsnip
RootVeg |Potatoes
Browns |Potatoes
請協助創建一個CTE以顯示上面...謝謝。
您的示例數據似乎不符合您的要求的輸出,除非我失去了一些東西。例如馬鈴薯是棕色的,棕色是根莖,根莖是雜貨......所以馬鈴薯不會在雜貨類別下面? – ZLK