按照sign_date 不为空的进行升序排序(不为空的排在最前),sign_date为空按照issu_date升序排序
select * from (
select '2011-09-14' as sign_date,'2011-09-01' as issu_date
union
select '2011-09-10' as sign_date,'2011-09-05' as issu_date
union
select '2011-09-12' as sign_date,'2011-09-02' as issu_date
union
select '' as sign_date,'2011-09-04' as issu_date
union
select '' as sign_date,'2011-09-05' as issu_date
) a 
order by sign_date ,issu_date目前的结果:                       
         2011-09-04
         2011-09-05
2011-09-10 2011-09-05
2011-09-12 2011-09-02
2011-09-14 2011-09-01
想要的结果:
2011-09-10        2011-09-04
2011-09-12 2011-09-05
2011-09-14 2011-09-05
         2011-09-02
         2011-09-01

解决方案 »

  1.   

    来错板块了,你应该去SQL板块,那边高手多
      

  2.   

    select * from (
    select 1 as num,* from xxx where xxx is not null order by xxx
    union
    select 2 as num* from xxx where xxx is null order by xxx) order by num仅供参考
      

  3.   

    按你那样写基本不能实现,你可以用Case判断,如果为空的话你给他一个可能的最大日期。这样排序就没问题了
      

  4.   

    create table tt
    (
    sign_date nvarchar(20),
    issu_date nvarchar(20)
    )insert into tt
    select null,'2011-09-04' union all
    select null,'2011-09-05' union all
    select '2011-09-10','2011-09-05' union all
    select '2011-09-12','2011-09-02' union all
    select '2011-09-14','2011-09-01'
    select * from (select top 10 * from tt where sign_date is not null order by sign_date) as a
    union all
    select * from (select top 10 * from tt where sign_date is null order by issu_date) as b
      

  5.   

    如果就单单一句SQL,还真不知道怎么弄,继续关注
      

  6.   


    select case when sign_date='' then'NULL' else sign_date end sign_date,issu_date from (select '2011-09-14' as sign_date,'2011-09-01' as issu_dateunionselect '2011-09-10' as sign_date,'2011-09-05' as issu_date
    union
    select '2011-09-12' as sign_date,'2011-09-02' as issu_date
    union
    select '' as sign_date,'2011-09-04' as issu_date
    union
    select '' as sign_date,'2011-09-05' as issu_date) a order by sign_date ,issu_date