--不太明白楼主的意思。不知这个对你有无帮助
declare @t table(A2 varchar(20),A3 varchar(20))
insert into @t
select 'a','c' union
select 'd','b' union
select 'g','a' union
select 'z','f'declare @a int
select @a=2
select * from @t
order by case @a when 1 then A2 else A3 end desc
declare @t table(A2 varchar(20),A3 varchar(20))
insert into @t
select 'a','c' union
select 'd','b' union
select 'g','a' union
select 'z','f'declare @a int
select @a=2
select * from @t
order by case @a when 1 then A2 else A3 end desc
--借用临时表create table #a (订单编号 varchar(10) , status bit , 采购员 varchar(10), primary key(订单编号)) insert into #a (订单编号,status,采购员) values('1',1,'sa')
insert into #a (订单编号,status,采购员) values('2',1,'sa')
insert into #a (订单编号,status,采购员) values('3',1,'sa')
insert into #a (订单编号,status,采购员) values('4',1,'sa')
insert into #a (订单编号,status,采购员) values('5',1,'sa')
insert into #a (订单编号,status,采购员) values('6',1,'sa')insert into #a (订单编号,status,采购员) values('21',1,'zz')
insert into #a (订单编号,status,采购员) values('22',1,'zz')
insert into #a (订单编号,status,采购员) values('23',1,'zz')insert into #a (订单编号,status,采购员) values('11',1,'yy')
insert into #a (订单编号,status,采购员) values('12',1,'yy')
insert into #a (订单编号,status,采购员) values('13',1,'yy')
insert into #a (订单编号,status,采购员) values('14',1,'yy')
insert into #a (订单编号,status,采购员) values('15',1,'yy')
insert into #a (订单编号,status,采购员) values('16',1,'yy')declare @count int, @s varchar(8000)set @count = 5
set @s='select top ' + cast(@count as varchar(20)) + '*
into #tp1
from #aselect identity(int,1,1) AS AutoID,*
into #tp2
from #tp1
order by 订单编号 desc --降序,或用asc升序insert into #tp2
select *
from #a
where 订单编号 not in (select 订单编号 from #tp2)select 订单编号, status, 采购员 from #tp2 order by AutoIDdrop table #tp1,#tp2'exec (@s)drop table #a
FROM dbo.offers在offers中有50000条记录
现在要得到这样的结果
把离现在两天之内的买的信息在前面显示
用offertype(买,卖)排序
后面的不排序