34,590
社区成员
发帖
与我相关
我的任务
分享
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([单双] varchar(4),[号码] int)
insert [tb]
select '单号',1 union all
select '单号',3 union all
select '单号',5 union all
select '双号',6 union all
select '双号',4 union all
select '双号',2
go
select * from tb
order by case when 单双='单号' then 1 else 2 end,
case when 单双='单号' then 号码 else -号码 end desc
/**
单双 号码
---- -----------
单号 5
单号 3
单号 1
双号 2
双号 4
双号 6
(6 行受影响)
**/