相关疑难解决方法(0)

具有排名功能的递归cte

如何在递归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

为什么没有排名?告诉我我的错误

t-sql sql-server recursive-query

2
推荐指数
1
解决办法
8215
查看次数

标签 统计

recursive-query ×1

sql-server ×1

t-sql ×1