0

试图让产品在树下几个层次......它不起作用。

选择Products.* 从 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 回答