递归问题解决方法,求大神帮帮忙!!
)
SELECT
*
FROM CC;
[解决办法]
WITH cte AS
(
SELECT ID,ItemCode,BOMUsage,1 AS leve FROM
(
SELECT aa.ID,aa.ItemCode,aa.BOMUsage FROM aa
JOIN bb ON aa.ItemCode=bb.VerID AND aa.BOMUsage=bb.BOMUsg
)a
UNION ALL
SELECT b.ID,b.ItemCode,b.BOMUsage,cte.leve+1 AS leve
FROM
(
SELECT aa.ID,aa.ItemCode,aa.BOMUsage FROM aa
JOIN bb ON aa.ItemCode=bb.VerID AND aa.BOMUsage=bb.BOMUsg
)b JOIN cte ON b.ID=cte.ItemCode
)
SELECT * FROM cte