当前位置: 代码迷 >> Sql Server >> 问个排序的有关问题
  详细解决方案

问个排序的有关问题

热度:25   发布时间:2016-04-27 15:49:23.0
问个排序的问题


中文¥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( ', '+字段+ ', ', ', '[email protected]+ ', ')
------解决方案--------------------
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
中文
*/
  相关解决方案