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条件排序么?该怎么写呢?

解决方案 »

  1.   

    select a from 表 where (a='xx' or a='zz' or a='yy')
    order by charindex(a,'xx,zz,yy')
      

  2.   

    select a from 表 where (a='xx' or a='yy' or a='zz') 
    ORDER BY A ?
      

  3.   

    select a from 表 where (a='xx' or a='yy' or a='zz') 
    ORDER BY CHARINDEX(A,'XX,ZZ,YY')
      

  4.   


    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
      

  5.   

    select a from 表 where (a='xx' or a='yy' or a='zz') 
     order by a
      

  6.   

    declare @a varchar(10),@b varchar(10),@c varchar(10),@s varchar(8000)
    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 控制
      

  7.   

    select
     a 
    from 
     tb 
     where
     a='xx' or a='zz' or a='yy' 
    order by 
     charindex(a,'xx,zz,yy')
      

  8.   


    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
      

  9.   


    select a from 表 where a="xx"
    union all select a from 表 where a="zz"
    union all select a from 表 where a="yy"