0

是否可以使用 TSQL 实现以下结果?数据的输入 表格中包含三个字段:serviceId,stationId,SeqNo 每个服务可以有多个站,并且按照 SeqNo 顺序排列 例如,服务 1 包含

stationId   SeqNo
A   1
B   2
C   3
D   4

服务 2

A   1
C   2
D   3
E   4
F   5

服务 3

A   1
B   2
C   3

我试图达到的是这样的结果

stationId   SeqNo
A   1
B   2
C   3
D   4
E   5
F   6
4

1 回答 1

0

您可以将查询编写为:

with CTE as 
(
select min(serviceid) as minserviceid , stationId,max(SeqNo) as maxSeqNo
from T1
group by stationId
),
CTE1 as 
(
select stationId, DENSE_RANK() over(order by stationId,maxSeqNo ) as rnk
from CTE
)
select stationId , rnk as SeqNo from CTE1
于 2013-10-31T06:12:29.037 回答