0

製品をツリーの 2 つ下のレベルに移動しようとしています... うまくいきません。

SELECT Products.* FROM Products

            LEFT JOIN   `Product_Categories` C
                ON  `Products`.`Category_ID` = C.`ID`
                OR  `Products`.`Sub_Category_ID` = C.`ID`
                OR  `Products`.`Sub_Category2_ID` = C.`ID`

            LEFT JOIN   `Product_Categories` C2
                ON      C.`ID` = C2.`Parent_ID`

            LEFT JOIN   `Product_Categories` C3
                ON      C2.`ID` = C3.`Parent_ID`

            LEFT JOIN   `Product_Categories` C4
                ON      C3.`ID` = C4.`Parent_ID`

            LEFT JOIN   `Product_Categories` C5
                ON      C4.`ID` = C5.`Parent_ID`

            LEFT JOIN   `Product_Categories` C6
                ON      C5.`ID` = C6.`Parent_ID`

            WHERE       `Products`.`Is_Master_Product` = 'Yes'
                AND     `Products`.`Is_Published` = 'Yes'
                AND     (`Products`.`Category_ID` = '29'
                        OR      `Products`.`Sub_Category_ID` = '29'
                    OR      `Products`.`Sub_Category2_ID` = '29')
            GROUP BY    `Products`.`Name`
            ORDER BY    `Products`.`Name` ASC
4

2 に答える 2

0
SELECT `Products`.*
            FROM        `Products`

            LEFT JOIN   `Product_Categories` C
                ON  `Products`.`Category_ID` = C.`ID`
                OR  `Products`.`Sub_Category_ID` = C.`ID`
                OR  `Products`.`Sub_Category2_ID` = C.`ID`

            LEFT JOIN   `Product_Categories` C2
                ON      C.`ID` = C2.`Parent_ID`

            LEFT JOIN   `Product_Categories` C3
                ON      C2.`ID` = C3.`Parent_ID`

            LEFT JOIN   `Product_Categories` C4
                ON      C3.`ID` = C4.`Parent_ID`

            LEFT JOIN   `Product_Categories` C5
                ON      C4.`ID` = C5.`Parent_ID`

            LEFT JOIN   `Product_Categories` C6
                ON      C5.`ID` = C6.`Parent_ID`

            WHERE       `Products`.`Is_Master_Product` = 'Yes'
                AND     `Products`.`Is_Published` = 'Yes'
                AND     (C.`Parent_ID` = '$category_ID'
                    OR  C.`ID` = '$category_ID')
            GROUP BY    `Products`.`Name`
            ORDER BY    `Products`.`Name` ASC
于 2013-06-30T01:30:58.637 に答える
-1

テーブル スキーマ、サンプル データを指定します。多分ストアドプロシージャはより良いアプローチになるでしょうか?

于 2013-06-30T00:55:36.997 に答える