如何增加每组字母
How to increment a letter per group
我有一个容器列表(超过 2000 行),我想将其分成多个比较项
Code Name Compartments
10 10 feet 1
15 15 feet 1
25 25 feet 2
100 100 feet 3
150 150 feet 2
我做了这个查询来实现那个
select *
from Containers c
inner join master.dbo.spt_values b on b.type = 'P' and b.number < c.Compartments
得到
Code Name Compartments
10 10 feet 1
15 15 feet 1
25 25 feet 2
25 25 feet 2
100 100 feet 3
100 100 feet 3
100 100 feet 3
150 150 feet 2
150 150 feet 2
现在我想在代码上添加一个自增字母,但是每组都是这样。
Code Name Compartments
10A 10 feet 1
15A 15 feet 1
25A 25 feet 2
25B 25 feet 2
100A 100 feet 3
100B 100 feet 3
100C 100 feet 3
150A 150 feet 2
150B 150 feet 2
我在考虑使用隔间的数量或添加标识列来添加 anm 增量 char(64),但我无法弄清楚如何使每组增量
select Code + CHAR(Compartments + 64), *
from Containers c inner join master.dbo.spt_values b on b.type = 'P' and
b.number < c.Compartments
这对你有用,但记得在 26 之后检查,意思是当你到达 'Z' 时会发生什么。
select Code + CHAR(ROW_NUMBER() OVER(PARTITION BY code ORDER BY name ASC) + 64), *
from Containers c inner join master.dbo.spt_values b on b.type = 'P' and
b.number < c.Compartments
我有一个容器列表(超过 2000 行),我想将其分成多个比较项
Code Name Compartments
10 10 feet 1
15 15 feet 1
25 25 feet 2
100 100 feet 3
150 150 feet 2
我做了这个查询来实现那个
select *
from Containers c
inner join master.dbo.spt_values b on b.type = 'P' and b.number < c.Compartments
得到
Code Name Compartments
10 10 feet 1
15 15 feet 1
25 25 feet 2
25 25 feet 2
100 100 feet 3
100 100 feet 3
100 100 feet 3
150 150 feet 2
150 150 feet 2
现在我想在代码上添加一个自增字母,但是每组都是这样。
Code Name Compartments
10A 10 feet 1
15A 15 feet 1
25A 25 feet 2
25B 25 feet 2
100A 100 feet 3
100B 100 feet 3
100C 100 feet 3
150A 150 feet 2
150B 150 feet 2
我在考虑使用隔间的数量或添加标识列来添加 anm 增量 char(64),但我无法弄清楚如何使每组增量
select Code + CHAR(Compartments + 64), *
from Containers c inner join master.dbo.spt_values b on b.type = 'P' and
b.number < c.Compartments
这对你有用,但记得在 26 之后检查,意思是当你到达 'Z' 时会发生什么。
select Code + CHAR(ROW_NUMBER() OVER(PARTITION BY code ORDER BY name ASC) + 64), *
from Containers c inner join master.dbo.spt_values b on b.type = 'P' and
b.number < c.Compartments