create table tbtime
(
id int identity(1,1) primary key,
gethour int
)insert into tbtime values(4)
insert into tbtime values(1)
insert into tbtime values(25)
insert into tbtime values(18)
SELECT '今天' as [date] , * FROM tbtime WHERE gethour >=16
UNION
SELECT '明天' as [date], * FROM tbtime WHERE gethour <=16
ORDER BY [date],gethour
查询出来的结果是:
今天  4  18
今天  3  25
明天  2   1
明天  1   4
===============
他order by date的时候 今天和明天都as date了。
但是为什么我把今天和明天互换了后,他还是今天在明天的前面。
我朋友说是因为今天(j)>明天(m)

解决方案 »

  1.   

    order by name collate Chinese_PRC_CS_AS_KS_WS 看你数据库的排序规则
      

  2.   

     
    --默认是按拼音排序的吧
     ORDER BY [date] collate Chinese_PRC_CS_AS_KS_WS
    ---按笔画排序
    ORDER BY [date] collate Chinese_PRC_Stroke_CS_AS_KS_WS
    ---楼主可以百度下排序规则
      

  3.   

    http://wenku.baidu.com/view/01f1e7e9856a561252d36fd3.html
    你的意思就是这个吧,看不大懂。
    那个今天在明天前面是为什么2L我就是想问他那个今天和明天排序为什么今天在明天的前面。
    这中间是怎么一回事。
      

  4.   

    http://jonsion.javaeye.com/blog/519038
    这个比较详细
      

  5.   

    最后的 order by 是针对整个记录集作用的,相当于:
    select * from
    (
    SELECT '今天' as [date] , * FROM tbtime WHERE gethour >=16
    UNION
    SELECT '明天' as [date], * FROM tbtime WHERE gethour <=16
    ) t
    ORDER BY [date],gethour如果是问“今”为什麽排在“明”之前,我也想知道,我更想知道为什麽是abcdef,而不是bfdeac。