如果我的排序字段里有百分号该怎么写呢
比如说select * from tb_test order by ac asc
其中 ac 的值都为 52.2% 65.4% 54.8%
该怎么排序呢
直接这样写。 好像排序不起作用。
------解决方案--------------------select * from tb_test order by Convert(float,replace(ac, '% ', ' ')) asc
------解决方案--------------------create table temp (A int, B int, C varchar(10))
insert temp
select 10, 3, '4.5% ' union all
select 31, 9, '3.2% ' union all
select 12, 8, '2.1% '
select * from temp order by left(c,len(c)-1) asc
------解决方案--------------------可以起作用啊
declare @tb_test table(ac varchar(10))
insert into @tb_test
select '52.2% '
union select '65.4% '
union select '54.8% '
select * from @tb_test order by ac asc
------解决方案--------------------select * from tb_test order by Convert(numeric(9,2),replace(ac, '% ', ' ')) asc
------解决方案--------------------select * from tb_test order by Cast(replace(ac, '% ', ' ') as numeric(9,2)) asc