Sql递归查询错误

时间:2015-08-19 02:33:29

标签: sql-server oracle sorting group-by recursive-query

WITH BomTree (
    ITEMNO
    ,[DESC]
    ,BOMNO
    ,BUILDQTY
    ,UNIT
    ,COMPONENT
    ,[Comp Desc]
    ,[Comp-Qty]
    ,COMPBOMNO
    ,Depth
    )
AS (
    SELECT bomh.ITEMNO
        ,itm1.DESC]
        ,bomh.BOMNO
        ,bomh.BUILDQTY
        ,bomh.UNIT
        ,bomd.COMPONENT
        ,itm.[DESC] [Comp Desc]
        ,bomd.QTY [Comp-Qty]
        ,bomd.COMPBOMNO
        ,0 AS Depth
    FROM ICBOMH bomh
    INNER JOIN ICBOMD bomd ON bomh.BOMNO = bomd.BOMNO
        AND bomh.ITEMNO = bomd.ITEMNO
    INNER JOIN ICITEM itm1 ON bomd.ITEMNO = itm1.ITEMNO
    INNER JOIN ICITEM itm ON bomd.COMPONENT = itm.ITEMNO
    WHERE bomd.BOMNO = '01'
        AND bomd.ITEMNO = '300060397'

    UNION ALL

    SELECT bomh.ITEMNO
        ,itm1.DESC]
        ,bomh.BOMNO
        ,bomh.BUILDQTY
        ,bomh.UNIT
        ,bomd.COMPONENT
        ,itm.[DESC] [Comp Desc]
        ,(t.[Comp-Qty] * bomd.QTY) AS [Comp-Qty]
        ,bomd.COMPBOMNO
        ,t.Depth + 1 AS Depth
    FROM ICBOMH bomh
    INNER JOIN ICBOMD bomd ON bomh.BOMNO = bomd.BOMNO
        AND bomh.ITEMNO = bomd.ITEMNO
    INNER JOIN ICITEM itm1 ON bomd.ITEMNO = itm1.ITEMNO
    INNER JOIN ICITEM itm ON bomd.COMPONENT = itm.ITEMNO
    INNER JOIN BomTree AS t ON bomd.ITEMNO = t.COMPONENT
    )
SELECT ITEMNO
    ,[DESC]
    ,BOMNO
    ,BUILDQTY
    ,UNIT
    ,COMPONENT
    ,[Comp Desc]
    ,[Comp-Qty]
    ,COMPBOMNO
    ,Depth
FROM BomTree
GROUP BY ITEMNO
    ,[DESC]
    ,BOMNO
    ,BUILDQTY
    ,UNIT
    ,COMPONENT
    ,[Comp Desc]
    ,[Comp-Qty]
    ,COMPBOMNO
    ,Depth;
  

错误:锚点和递归部分之间的类型不匹配   递归查询“BomTree”的列“Comp-Qty”。

1 个答案:

答案 0 :(得分:0)

首先,此错误表示两个联合查询中相同列之间的数据类型不匹配。为了解决这个问题,您可以重写您的查询:

std::string playerName;