如何在递归cte中使用排名函数?这是一个简单的例子,显示了我正在尝试做的事情:
with cte as ( select 1 a, 1 b union all select 1, 2 union all select 2, 3 union all select 2, 4 ) , rcte (a, b, c, d) as ( select a, b, cast(0 as int), 1 from cte union all select a, b, cast(ROW_NUMBER() over (partition by a order by b) as int), d+1 from rcte where d < 2 ) select * from rcte where d=2 order by a, b
为什么没有排名?告诉我我的错误