分批排序.txt

来自「SQL语言常用的一些命令各代码」· 文本 代码 · 共 30 行

TXT
30
字号
/*分批排序*/
/*方法1*/
declare @a table(id int)
declare @b int
select @b=1
while @b<=10
begin
insert into @a select @b
select @b=@b+1
end
--select * from @a
declare @c table(id int)
insert into @c select top 5 *  from @a 
declare @d table(id int)
insert into @d select * from @c order by id desc
insert into @d select  * from @a  where id not in (select id from @d)
select * from @d

/*方法2*/
create table #shuzi(id int)
insert into #shuzi select 1
insert into #shuzi select 5
insert into #shuzi select 3
insert into #shuzi select 9
insert into #shuzi select 11
insert into #shuzi select 10
insert into #shuzi select 13
select a.id from  ( select top 7 id,sign(id-6) as k ,abs(id-6) as m from #shuzi 
order by sign(id-6),abs(id-6) ) a  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?