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

order 排序有关问题

2012-03-06 
order 排序问题有一个字段是这样的格式850×495×475,我想按第一个数字(比如850,有时候是3位,有时候是4位)排

order 排序问题
有一个字段是这样的格式850×495×475,我想按第一个数字(比如850,有时候是3位,有时候是4位)排序.没法用left(guige,3)来排序.

请问怎么办?

我不太清楚sql语句对字符串的操作还有哪些函数可以用的.


[解决办法]
use lairui

select * from sky order by left(lairui,(len(lairui)-charindex( '* ',lairui))) desc
[解决办法]
if object_id( 't1 ') is not null
drop table t1

create table t1(id int identity(1,1),guige varchar(20))
insert into t1 select '850×495×475 '
union all select '50×495×475 '
union all select '1850×495×475 '
union all select '2850×495×475 '
union all select '3850×495×475 '
union all select '80×495×475 '
union all select '8500×495×475 '

select * from t1 order by cast(left(guige,charindex( '× ',guige)-1) as int)

drop table t1 --

(所影响的行数为 7 行)

id guige
----------- --------------------
2 50×495×475
6 80×495×475
1 850×495×475
3 1850×495×475
4 2850×495×475
5 3850×495×475
7 8500×495×475

(所影响的行数为 7 行)

热点排行