MySQL 获取子分类ID的所有父分类ID和Name的集合
1 CREATE DEFINER=`sa`@`%` PROCEDURE `proc_Product_leimu_ParentIds`( 2 IN pID INT 3 ) 4 BEGIN 5 SELECT T2.ID, T2.Name FROM ( SELECT @r AS _id, (SELECT @r := ParentID FROM product_leimu WHERE ID = _id) AS ParentID, @l := @l + 1 AS lvl FROM (SELECT @r := pID, @l := 0) vars, product_leimu h WHERE @r <> 0) T1 6 JOIN product_leimu T2 ON T1._id = T2.ID ORDER BY T1.lvl DESC; 7 END
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。