我有下表:
create table #tbl
(
product_id nvarchar(50)
)
insert into #tbl values ('011014-A11')
insert into #tbl values ('011014-A10')
insert into #tbl values ('011014')
insert into #tbl values ('011014-A1')
insert into #tbl values ('011014-A2')
我想这样排序产品 ID(从小到大):
011014
011014-A1
011014-A2
011014-A10
011014-A11
这是我尝试过的,但它不起作用:
select product_id
from #tbl
order by product_id desc
我该怎么做?
我如何才能获得最大的 product_id?
我试过了,但没用:
select top 1 product_id
from #tbl
order by product_id desc
最佳答案
尝试以下查询以按您预期的顺序获得结果。
Select product_id
From tbl --Please change table name to #tbl in your actual query
Order by len(product_id), product_id
关于SQL - 使用字母数字字符排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21048295/