這樣不行了
select * from table where isnull(optime,'')=''
union all
select * from table where isnull(optime,'')<>'' order by id desc

解决方案 »

  1.   

    select * from table where optime is null 
    union
    select * from table where optime is not null order by id desc
      

  2.   

    楼上两位,那样我已经试过了,不行的,结果也只是按照id来排!
    OPTIME的排序就和之前ID一样,是乱的,空的和不为空的混合着的!!
      

  3.   

    order by (case when optime is null then 0 else 1 end),id desc
      

  4.   

    若optime不为空时还要按它排序:
    order by (case when optime is null then 0 else 1 end),optime,id desc
      

  5.   

    select optime,id 
    from 表
    order by case when optime is null then optime else id end
      

  6.   

    to:pbsql(风云) 
    虽然我还没去试,但是为什么要在optime上处理,因为只是id的问题啊!
      

  7.   

    难道如果为NULL,就会出问题?非要转化一下!
      

  8.   

    select * from ttt order by
    (case when optime is null then 9999999 else id end) desc