日期:2014-05-17  浏览次数:20457 次

#XL黑色 #S黑色 #M黑色 #L黑色 #XXL黑色 排序问题
#XL黑色 #S黑色 #M黑色 #L黑色 #XXL黑色

如何才能 安装 

 #S黑色 #M黑色 #L黑色 #XL黑色 #XXL黑色   → 这样排序?


tks
排序

------解决方案--------------------

select * from (select '#XL黑色'a union all
select '#S黑色' union all
select '#M黑色' union all
select '#L黑色' union all
select '#XXL黑色')a
order by 
case a 
when '#S黑色' then 1 
when '#M黑色' then 2 
when '#L黑色' then 3 
when '#XL黑色' then 4 
when '#XXL黑色' then 5 end

------解决方案--------------------
这样改:
select * from (select '#XL'a union all
select '#S' union all
select '#M' union all
select '#L' union all
select '#XXL')a
order by 
case  
when a like '#XXL%' then 5
when a like '#XL%' then 4 
when a like '#L%' then 3 
when a like '#M%' then 2 
when a like '#S%' then 1 
end

这样,无论后面加什么字,都会按这样排序了。