--> 测试数据: #T if object_id('tempdb.dbo.#T') is not null drop table #T create table #T (ID int,鲜花名 varchar(4),类型 varchar(4)) insert into #T select 1,'玫瑰','高档' union all select 2,'玫瑰','中档' union all select 3,'月季','低档' union all select 4,'月季','低档' goselect * from #T order by case 类型 when '中档' then 1 when '低档' then 2 when '高档' then 3 endgo drop table #T/* ID 鲜花名 类型 ----------- ---- ---- 2 玫瑰 中档 3 月季 低档 4 月季 低档 1 玫瑰 高档(4 row(s) affected)*/
ID 鲜花名 类型 1 玫瑰 高档 2 玫瑰 中档 3 月季 低档 4 月季 低档 --select * from ta order by case 类型 when '中档' then 0 when '低档' then 1 else 2 end
if object_id('tempdb.dbo.#T') is not null drop table #T
create table #T (ID int,鲜花名 varchar(4),类型 varchar(4))
insert into #T
select 1,'玫瑰','高档' union all
select 2,'玫瑰','中档' union all
select 3,'月季','低档' union all
select 4,'月季','低档'
goselect *
from #T
order by case 类型 when '中档' then 1
when '低档' then 2
when '高档' then 3
endgo
drop table #T/*
ID 鲜花名 类型
----------- ---- ----
2 玫瑰 中档
3 月季 低档
4 月季 低档
1 玫瑰 高档(4 row(s) affected)*/
1 玫瑰 高档
2 玫瑰 中档
3 月季 低档
4 月季 低档
--select *
from ta
order by case 类型 when '中档' then 0 when '低档' then 1 else 2 end