表1  a   b  1  340
  0  320
  0  210
  1  329
  1  403
  0  322想先把a=1的按升序排列,然后a<>1的再按升序排列,该怎么写查询语句

解决方案 »

  1.   

    select a,b from 表1 order by a desc,b asc
      

  2.   

    select a,b from 表1 order by case a when 1 then 0 else 1 end,b asc
      

  3.   

    select a,b from 表1 order by case a when 1 then 0 else 1 end,b asc
      

  4.   

    select * from 表1 where a=1 order by b
    union all
    select * from 表1 where a<>1 order by b
      

  5.   

    create table #a(
    a int,
    b int)
    go
    insert into #a
    select 1,  340
    union all
    select 0,  320
    union all
    select 0,  210
    union all
    select 1,  329
    union all
    select 1,  403
    union all
    select 0 , 322
    go 
    select * from #a order by a desc,b asc--drop table #a