order by case when name='张三' then 0 else 1 end asc
select * from 表1 order by case when name='张三' then 0 else 1 end,其他排序字段
order by charindex('张三',NAME) desc
这样? create table test(name nvarchar(20)) insert test select N'赵六' union all select N'李四' union all select N'张三' union all select N'王五'select name from test order by case when name=N'张三' then 0 else 1 enddrop table testname -------------------- 张三 王五 赵六 李四
select * from (select a.*,type = '1' from a where name = '張三' union all select a.*,type = '0' from a where name <> '張三') order by desc
反了 order by charindex(NAME,'张三') desc
--借用一下数据 create table test(name nvarchar(20)) insert test select N'赵六' union all select N'李四' union all select N'张三' union all select N'王五'select name from test order by charindex(name,'张三') descdrop table test /* name -------------------- 张三 王五 赵六 李四(4 row(s) affected) */
order by case when name='张三' then 0 else 1 end asc 最合题意charindex(name,'张三') desc 有误差 name 是'张' 和 '张三' 那结果是一样的,有可能导致张排在前面 如果name是'三',就肯定会排在张三前面
from 表1
order by case when name='张三' then 0 else 1 end,其他排序字段
create table test(name nvarchar(20))
insert test select N'赵六'
union all select N'李四'
union all select N'张三'
union all select N'王五'select name from test
order by case when name=N'张三' then 0
else 1 enddrop table testname
--------------------
张三
王五
赵六
李四
select a.*,type = '0' from a where name <> '張三') order by desc
order by charindex(NAME,'张三') desc
create table test(name nvarchar(20))
insert test select N'赵六'
union all select N'李四'
union all select N'张三'
union all select N'王五'select name from test
order by charindex(name,'张三') descdrop table test
/*
name
--------------------
张三
王五
赵六
李四(4 row(s) affected)
*/
name 是'张' 和 '张三' 那结果是一样的,有可能导致张排在前面
如果name是'三',就肯定会排在张三前面