我在尝试创建父子层次结构时遇到了麻烦。
询问:
SELECT
ID,
[Manager Code],
Manager,
CASE WHEN [Manager Code] = 1 then
LAG(ID) over (order by [Manager Code] desc, ID, p_id) end as IDParentChild,
ROW_NUMBER() over (partition by ID order by [Manager Code] desc, ID, p_id) as RowNum
FROM Employee
WHERE ID IN ('90110000000','90110100000','90400000000')
桌子:
我有父母和 IDParentChild 的 ID,但我怎么不做父母子女关系?
Manager 代码中的 nr 1 代表经理,0 是员工。
mssql 服务器 2012