任何人都可以帮助我如何排序?
我有一个模式的动态列表,我想排序,它包含字母数字值和字母。Sql Server 2008中的字母数字排序
CREATE TABLE dbo.Pattern (Pattern varchar(50) NULL)
INSERT INTO dbo.Pattern (Pattern) VALUES ('A11')
INSERT INTO dbo.Pattern (Pattern) VALUES ('A12')
INSERT INTO dbo.Pattern (Pattern) VALUES ('A8')
INSERT INTO dbo.Pattern (Pattern) VALUES ('A2')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B6')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B21')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B10')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B3')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B100')
INSERT INTO dbo.Pattern (Pattern) VALUES ('B2')
INSERT INTO dbo.Pattern (Pattern) VALUES ('AA')
INSERT INTO dbo.Pattern (Pattern) VALUES ('BA')
INSERT INTO dbo.Pattern (Pattern) VALUES ('A20')
INSERT INTO dbo.Pattern (Pattern) VALUES ('AB')
INSERT INTO dbo.Pattern (Pattern) VALUES ('BB')
SELECT Pattern FROM dbo.Pattern ORDER BY Pattern
DROP Table dbo.Pattern
结果表明这样的:
A11
A12
A2
A20
A8
AA
AB
B10
B100
B2
B21
B3
B6
BA
BB
但我要表明的是这样的结果:
AA
A1
A2
A8
A11
A12
A20
AB
BA
B2
B3
B6
B10
B21
B100
BB
加1样本数据 – TheGameiswar
您可以定义所需结果背后的逻辑吗?为什么'AA'会出现在'B100'之后? “AAA”和“BA1”之间会先出现哪一个?为什么?如果你可以定义逻辑,我敢打赌,你很容易回答你自己的问题。 –
@TabAlleman,我已经编辑了应该为模式排序输出的结果的内容。 – itsMacyAnn