order by (case when charindex('米',itemName)>0 then 0 else 1 end), (case when charindex('米',itemName)>0 then convert(int,left(itemName,charindex('米',itemName)-1)) end)
把Order By ItemName改成如下:Order by case When IsNumeric(replace(itemName ,'米',''))=1 then Cast(replace(itemName ,'米','') as int) else 2147483647 End
create table tb(name nvarchar(32)) goinsert tb select '50米' union select '60米' union select '500米' union select '600米' union select '10米' union select '350米' union select '跳高'select * from tb /* name 50米 60米 500米 600米 10米 350米 跳高 */ select * from tb order by case when CHARINDEX('米',name)>0 then cast(left(name,CHARINDEX('米',name)-1)as int) else 999999999 end /* name 10米 50米 60米 350米 500米 600米 跳高 */drop table tb
order by (case when charindex('米',itemName)>0 then 0 else 1 end),
(case when charindex('米',itemName)>0 then convert(int,left(itemName,charindex('米',itemName)-1)) end)
create table tb(name nvarchar(32))
goinsert tb select '50米' union select '60米'
union select '500米' union select '600米'
union select '10米' union select '350米'
union select '跳高'select * from tb
/*
name
50米
60米
500米
600米
10米
350米
跳高
*/
select * from tb order by case when CHARINDEX('米',name)>0 then cast(left(name,CHARINDEX('米',name)-1)as int) else 999999999 end
/*
name
10米
50米
60米
350米
500米
600米
跳高
*/drop table tb
我项目架构是SSH
但是,我用Ireport 制作报表,并使用Struts2 的List集合作为数据源的时候
这个仍然是没有排序的呢
单独访问这个list集合,是已经排序了的。
谢谢,程序中已经实现,这样做是没有问题的
我项目架构是SSH
但是,我用Ireport 制作报表,并使用Struts2 的List集合作为数据源的时候
这个仍然是没有排序的呢
单独访问这个list集合,是已经排序了的。引用 3 楼 的回复:
SQL code那问题就不在数据库这里了。可以到JAVA 版里咨询