假设表T中有如下数据:字段A 字段B
a 1111111
a 2222222
a 3333333
a 4444444
b 1111111
b 2222222
b 3333333
b 4444444
b 5555555
c 1111111
c 2222222
c 3333333写一个存储过程,读取一条记录并返回A和B的值,然后将这条记录删掉,希望读出的顺序类似这样:
a 1111111
b 1111111
c 1111111
a 2222222
b 2222222
c 3333333
...这个存储过程该如何写呢?谢谢。
a 1111111
a 2222222
a 3333333
a 4444444
b 1111111
b 2222222
b 3333333
b 4444444
b 5555555
c 1111111
c 2222222
c 3333333写一个存储过程,读取一条记录并返回A和B的值,然后将这条记录删掉,希望读出的顺序类似这样:
a 1111111
b 1111111
c 1111111
a 2222222
b 2222222
c 3333333
...这个存储过程该如何写呢?谢谢。
where exists(select 1 from tb t where t.a=tb.a and t.b<tb.b)
select * , id=row_number() over(order by b) from tb t order by id , a
as
declare @a char(1),@b varchar(10)
select top 1 @a=a,@b=b
from tb
select @a,@b
delete from tb where a=@a and b=@b
2、select a,b from (select row=number() over(partition by b prder by a) K order by row
begin
delete tab
output deleted.*
where a=(select top 1 a from tab order by b,a)
and b=(select top 1 b from tab order by b,a)
end