select a from 表 where (a='xx' or a='yy' or a='zz')结果:
a
----
xx
yy
zz
select a from 表 where (a='xx' or a='zz' or a='yy')结果:
a
----
xx
zz
yyselect语句能按where条件排序么?该怎么写呢?
a
----
xx
yy
zz
select a from 表 where (a='xx' or a='zz' or a='yy')结果:
a
----
xx
zz
yyselect语句能按where条件排序么?该怎么写呢?
order by charindex(a,'xx,zz,yy')
ORDER BY A ?
ORDER BY CHARINDEX(A,'XX,ZZ,YY')
select a from 表 where (a='xx' or a='zz' or a='yy')
order by case a when 'xx' then 1 when 'zz' then 2 else 3 end
order by a
set @a='xx'
set @b='zz'
set @c='yy'
set @s='select a from 表 where ( a='''+@a+''' or a='''+@b+''' or a='''+@c+''')'
+' order by charindex(a,''@a+@b+@c'')'
exec (@s)
通过 @a @b @c 控制
a
from
tb
where
a='xx' or a='zz' or a='yy'
order by
charindex(a,'xx,zz,yy')
declare @mytb table(col1 char(3),col2 char(2),col3 decimal(3,0))
insert @mytb select 'xx','ac',3 union
select 'yy','ad',5 union
select 'zz','ab',6 union
select 'aa','b4',7 union
select 'bb','a4',8
select * from @mytb where (col2='ab' or col2='ac' or col2='ad') order by col2
select a from 表 where a="xx"
union all select a from 表 where a="zz"
union all select a from 表 where a="yy"