create table b
(
f1 varchar(10),
f2 varchar(10),
f3 varchar(10)
)insert into b values('a','b','c')
insert into b values('b','x','h')
insert into b values('a','t','f')
insert into b values('a','h','f')
insert into b values('n','c','a')
insert into b values('c','r','n')select * from b
order by f1,f3 desc
(
f1 varchar(10),
f2 varchar(10),
f3 varchar(10)
)insert into b values('a','b','c')
insert into b values('b','x','h')
insert into b values('a','t','f')
insert into b values('a','h','f')
insert into b values('n','c','a')
insert into b values('c','r','n')select * from b
order by f1,f3 desc
select * from 表
order by charindex(','+f3+',',',f,') desc,f1
declare @t table(f1 varchar(1),f2 varchar(1),f3 varchar(1))
insert into @t select 'a','b','c'
union all select 'b','x','h'
union all select 'a','t','f'
union all select 'a','h','f'
union all select 'n','c','a'
union all select 'c','r','n'
--测试语句
select * from @t
order by charindex(','+f3+',',',f,') desc,f1 --注意:这里可以指定显示顺序!
--结果(结果可能和你的完全不同,但按要求指定顺序后,是可以实现的!)
f1 f2 f3
---- ---- ----
a t f
a h f
a b c
b x h
c r n
n c a(所影响的行数为 6 行)order by f1,f3 desc
--测试环境
declare @t table(f1 varchar(1),f2 varchar(1),f3 varchar(1))
insert into @t select 'a','b','c'
union all select 'b','x','h'
union all select 'a','t','f'
union all select 'a','h','f'
union all select 'n','c','a'
union all select 'c','r','n'
--查询语句
select * from @t
order by charindex(','+f3+',',',f,c,h,a,n,') asc
--结果
f1 f2 f3
---- ---- ----
a t f
a h f
a b c
b x h
n c a
c r n(所影响的行数为 6 行)