sql order by中文记录如何排序
如:一,二,三,四,五,六,日
如何降序排列成:日,六,五,四,三,二,一
直接写order by 星期 desc   是按中文的拼音首字母降序排列的

解决方案 »

  1.   


    create table tempTab
    (
    tID varchar(10),
            tWeek   varchar(10)
    )
    insert into tempTab(tID,tWeek) values('1','星期一')
    insert into tempTab(tID,tWeek) values('2','星期二')
    insert into tempTab(tID,tWeek) values('3','星期三')
    insert into tempTab(tID,tWeek) values('4','星期四')
    insert into tempTab(tID,tWeek) values('5','星期五')
    insert into tempTab(tID,tWeek) values('6','星期六')
    insert into tempTab(tID,tWeek) values('7','星期日')
    select * from tempTab order by charindex(tWeek,'星期一,星期二,星期三,星期四,星期五,星期六,星期日') desc
    drop table tempTab
      

  2.   

    declare @t table([weekday] varchar(10))
    insert @t select '星期一'
    union all select '星期二'
    union all select '星期三'
    union all select '星期四'
    union all select '星期五'
    union all select '星期六'
    union all select '星期日'select * from @t
    order by case [weekday] when '星期一' then 1
                            when '星期二' then 2
                            when '星期三' then 3
                            when '星期四' then 4
                            when '星期五' then 5
                            when '星期六' then 6
                            when '星期日' then 7
    end desc/*
    (所影响的行数为 7 行)weekday    
    ---------- 
    星期日
    星期六
    星期五
    星期四
    星期三
    星期二
    星期一(所影响的行数为 7 行)
    */