有这样的数据:
notice_id      notice_order(char(2))
1                
2                1
3                3
4                2
5
查询结果后显示成这样的
notice_id      notice_order
2                 1
4                 2
3                 3
5

order不为空的,进行正排,列在上面...order为空的放在下面,按notice_id倒排(select NOTICE_ID,NOTICE_ORDER
from NOTICE
where NOTICE_ORDER is not null AND NOTICE_ORDER<>''
ORDER BY NOTICE_ORDER ASC
)
union all(select NOTICE_ID,NOTICE_ORDER
  from NOTICE
 where NOTICE_ORDER is null OR NOTICE_ORDER=''
ORDER BY NOTICE_ID DESC
)
我写的sql,有order的不会正排

解决方案 »

  1.   

    select NOTICE_ID,NOTICE_ORDER
    from NOTICE
    ORDER BY NOTICE_ORDER ASC,notice_id des ;
    试试,
      

  2.   

    ORDER BY NOTICE_ORDER ASC把NOTICE_ORDER 改成NOTICE_ID因为你的NOTICE_ORDER 是char型的。。怎么能正排那你的NOTICE_ID是int型的。。可以的~!
    给分吧~!
      

  3.   

    可是我要对order排序,而不是针对id
      

  4.   

    select * from (select * from NOTICE where notice_order is not null order by notice_order) union all select * from(select * from NOTICE where notice_order is null order by notice_id desc)
      

  5.   

    (select NOTICE_ID,NOTICE_ORDER
    from NOTICE
    where NOTICE_ORDER is not null AND NOTICE_ORDER<>''
    ORDER BY NOTICE_ORDER
    )
    union all(select NOTICE_ID,NOTICE_ORDER
      from NOTICE
     where NOTICE_ORDER is null OR NOTICE_ORDER=''
    ORDER BY NOTICE_ID DESC
    )
    ORDER BY NOTICE_ORDER DESC
      

  6.   


    不行,错误:Incorrect usage of UNION and ORDER BY
      

  7.   

    select NOTICE_ID ,NOTICE_ORDER from 

    (select * from NOTICE 
    where NOTICE_ORDER  is not null AND NOTICE_ORDER<>''
    order by NOTICE_ORDER )
    union all 
    (select * from 
    (
    select * from NOTICE where NOTICE_ORDER is null OR NOTICE_ORDER=''
    order by NOTICE_ID desc ) as A
    )
    ) as B
    我把你写的SQL稍改了下,可是也没有对order正排
      

  8.   

    select NOTICE_ID ,NOTICE_ORDER from 

        (select * from 
           (
            select * from NOTICE where NOTICE_ORDER  is not null AND NOTICE_ORDER<>''
            order by NOTICE_ORDER ) as a
         )
        union all 
        (select * from 
            (
            select * from NOTICE where NOTICE_ORDER is null OR NOTICE_ORDER=''
            order by NOTICE_ID desc ) as b
        )
    ) as c;
      

  9.   

    NND,下午要去华科笔试,现在浑身都不舒服。。跑那么远。。郁闷啊
      

  10.   

    select * from (select * from table2 where notice_order <>'' order by notice_order asc)t union all select * from(select * 
    from table2 where notice_order='' order by notice_id desc)t要是不对的话 ,我估计你得重装数据库了