我有以下格式的数据:
FromStateID ToStateID Seconds
1 2 10
2 3 20
3 4 15
4 5 5
我需要以下输出
FromStateID ToStateID Seconds
1 2 10
2 3 20
3 4 15
4 5 5
1 3 10+20
1 4 10+20+15
1 5 10+20+15+5
2 4 20+15
2 5 20+15+5
3 5 15+5
此输出显示所用的总时间 FromStateId
至 ToStateId
按时间顺序排列。
请帮忙。
2条答案
按热度按时间m2xkgtsf1#
我认为这是一个递归的cte,它遵循以下链接:
这是一把小提琴。
4ktjp1zp2#
@gordon linoff是更好的解决方案。下面是实现同样目标的另一种选择。
您可以使用交叉连接和分组方式来实现这一点