我正在执行以下查询:
WITH rg(id, childid, NAME)
AS (SELECT id,
0 ChildID,
NAME
FROM kuaf
WHERE id = 1000
UNION ALL
SELECT c.id,
c.childid,
k.NAME
FROM kuafchildren c
JOIN rg p
ON ( c.childid = p.id )
JOIN kuaf k
ON ( c.id = k.id ))
SELECT DISTINCT ka.id
FROM rg,
lm_approvals app
JOIN kuaf ka
ON ( ka.id = app.useridentifier )
JOIN dtree dt
ON ( dt.dataid = app.dataid )
WHERE app.dataid = 25773
AND app.isapproved = 0
AND Replace(ka.NAME, ka.type + '_', dt.ownerid + '_') = rg.NAME
但是我结束了以下错误:
类型不在锚和列中的递归部分之间匹配 " childID的"递归查询" rg"。
答案 0 :(得分:1)
如果按如下方式更改resursive CTE的第一个SELECT或锚点部分,它将起作用
sudo service cloudstack-management restart
这是我们通常使用空字符串或在此步骤中选择NULL的情况。 因此,CTE
需要明确定义锚点类型答案 1 :(得分:0)
我自己没试过这个
从文件来看
有必要明确转换
0类型,如kuafchildren.childid
通过
CAST(表达式AS data_type [(长度)])
要么
CONVERT(data_type [(length)],表达式[,style])
表达式 - 0
data_type [(length)])与kuafchildren.childid相同
您可以尝试改写 0 ChildID kuaf.id * 0 ChildID 如果kuaf.id的类型与kuafchildren.childid
相同,则可能会有效答案 2 :(得分:0)
试试这个......
;WITH CTE RG AS (
SELECT Id,
0 AS 'ChildId',
Name
FROM Kuaf
WHERE id = 1000
UNION ALL
SELECT C.Id,
C.ChildId,
C.Name
FROM KuafChildren C
INNER JOIN RG ON (C.ChildId = RG.ChildId)
)
SELECT ...
我假设ChildId列数据类型是int