我有如下的东西
declare @t table (id int identity,Price decimal(6,2))
insert into @t
select 17.5 union all
select 10.34 union all
select 2.0 union all
select 34.5
Run Code Online (Sandbox Code Playgroud)
现在,如果我编写如下查询
;with cte(id, price) as
(
select id, price
from @t
union all
select cte.id, cte.price + t.price
from cte
join @t t
on cte.id < t.id
)
select *
from @t
Run Code Online (Sandbox Code Playgroud)
我在运行时收到以下错误:
锚点和递归部分之间的类型不匹配......
我什至在类型转换(到十进制)后尝试了相同的操作,但结果相同......
但是,如果我类型转换为 int 它可以工作......但情况不应该是这样的(:
我有以下输入
PlayerID MatchPlayed RunsMade
-------- ----------- --------
1 10 200
2 5 100
3 8 24
4 30 50
Run Code Online (Sandbox Code Playgroud)
输出将是
Combined Players Combined Match Played Combined runs Made
---------------- --------------------- ------------------
1 10 200
1,2 15 300
1,3 18 224
1,4 40 250
1,2,3 23 324
1,2,4 45 350
1,3,4 48 274
1,2,3,4 53 374
2 5 100
2,3 13 124
2,4 35 150
2,3,4 43 174
3 8 24
3,4 38 74
4 30 50
Run Code Online (Sandbox Code Playgroud)
该组合匹配玩过列的值的总和这些球员一场比赛列 …