首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

这样的order by 应当怎样写解决方案

2012-03-24 
这样的order by 应当怎样写某table有一varchar字段mark_code,数据格式如下#1,#2,#3,……,#10,……,请问怎样写s

这样的order by 应当怎样写
某table有一varchar字段mark_code,数据格式如下#1,#2,#3,……,#10,……,请问怎样写sql的order   by   使select的结果如“#1,#2,#3,……,#10,……”排列?

[解决办法]
ORDER BY SUBSTRING(mark_code,2)+0
[解决办法]
order by replace(mark_code, '# ',1)
[解决办法]
order by cast(substring(name,2) as unsigned) asc
[解决办法]
declare @myTable table(a varchar(10))
insert into @myTable
select '#1 ' union all
select '#2 ' union all
select '#3 ' union all
select '#4 ' union all
select '#5 ' union all
select '#6 ' union all
select '#7 ' union all
select '#9 ' union all
select '#10 ' union all
select '#11 '

select * from @myTable order by convert(int,substring(a,2,len(a)))

热点排行