日期:2014-05-18  浏览次数:20464 次

问个排序的问题


中文¥1
中文¥2
中文

如何让SELECT出来的语句如上排序

------解决方案--------------------
select * from tb where 字段 = '中文¥1 '
union all
select * from tb where 字段 = '中文¥2 '
union all
select * from tb where 字段 = '中文 '

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


select * from tbName
order by
case colName when '中文¥1 ' then 1 when '中文¥2 ' then 2 when '中文 ' then 3 end
------解决方案--------------------
declare @str varchar(1000)
set @str= '中文¥1,中文¥2,中文 '
select * from 表 order by charindex( ', '+字段+ ', ', ', '+@str+ ', ')
------解决方案--------------------
declare @t table(c1 nvarchar(100))
insert @t
select '中文¥1 ' union all
select '中文¥3 ' union all
select '中文¥2 ' union all
select '中文¥4 ' union all
select '中文 '

select * from @t
order by case when charindex( '¥ ',c1)> 0 then 0 else 1 end,c1

/*
c1
----------
中文¥1
中文¥2
中文¥3
中文¥4
中文
*/