如果是select isnull(c.rsvalue,c.gweva) AS eva from tbeva的值就象上面说的 A C B+ C+ B如果order by left(eva,1),len(eva) desc会报错的
order by left(isnull(c.rsvalue,c.gweva),1),len(isnull(c.rsvalue,c.gweva)) desc
--> 数据库版本: --> 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]
還有B- ? 在order by中加case when处理吧
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
from tbeva的值就象上面说的 A C B+ C+ B如果order by left(eva,1),len(eva) desc会报错的
--> 数据库版本:
--> 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]
在order by中加case when处理吧
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