6,129
社区成员
发帖
与我相关
我的任务
分享
SELECT * FROM DBO.TB ORDER BY LEFT(ph,6)
补充下查询结果
091101-1
091101-2
091102
091103
091104
create table tab_a
(
ph varchar(30)
)
delete from tab_a
insert into tab_a
select '091103' union all
select '091101-1' union all
select '091104' union all
select '091102' union all
select '091101-2'
select *from tab_a order by ph
--我自己建立个表存放测试数据 数据的顺序我刻意错乱 插入
--查询只需要 order by ph 就行了
order by left(ph,4),substring(ph,5,2),right(ph,len(ph)-charindex('-',ph))
order by ph,replace(right(ph,len(ph)-7),'-','')