如果 字段 peva有 A  C  B+ C+  B
如果order by peva
得到的是 A  B  B+ C C+
如果想得到 A B+  B  C+  C得怎么弄的?

解决方案 »

  1.   

    order by left(peva,1),len(peva) desc
      

  2.   

    如果是select  isnull(c.rsvalue,c.gweva)   AS eva 
          from tbeva的值就象上面说的  A C B+ C+  B如果order by left(eva,1),len(eva) desc会报错的
      

  3.   

    order by left(isnull(c.rsvalue,c.gweva),1),len(isnull(c.rsvalue,c.gweva)) desc
      

  4.   


    --> 数据库版本:
    --> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
    --> 测试数据:[TB]
    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]') 
    AND type in (N'U')) 
    DROP TABLE [TB]
    GO---->建表
    create table [TB]([action] varchar(4))
    insert [TB]
    select 'A' union all
    select 'B' union all 
    select 'C' union all
    select 'B+'union all
    select 'C+'
    GO--> 查询结果
    with a as ( 
    select *,ROW_NUMBER()over(partition by left([action],1) order by [action]) as id
    from TB )
    select [action] from a 
    order by left([action],1),id desc --查询结果
    A
    B+
    B
    C+
    C--> 删除表格
    --DROP TABLE [TB]
      

  5.   

    還有B- ?
    在order by中加case when处理吧
      

  6.   


    select code,code1=code,id=1 from tb where charindex('+',code)<=0
    union all
    select code,code1=cast(left(code,1) as varchar(20)),id=0 from tb where charindex('+',code)>0
    order by code1,id
      

  7.   

    order by left(peva,1),len(peva) desc