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

问个排序的有关问题

2012-03-05 
问个排序的问题如中文¥1中文¥2中文如何让SELECT出来的语句如上排序[解决办法]select * from tb where 字段

问个排序的问题


中文¥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
中文
*/

热点排行