mysql实现分组排序并赋予序号的存贮过程
时间:2011-05-10 来源:思维的边疆
1 drop procedure set_rank;
2 create procedure set_rank()
3 begin
4 set @i=1;
5 set @number=(select count(1) from suppliers_performance);
6 update suppliers_performance set score_rank=0;
7
8 while @i<@number
9 do
10 begin
11 update suppliers_performance set score_rank=@i where id in (select id from (select id from suppliers_performance where score_rank=0 order by score limit 1) b);
12 set @i=@i+1;
13 end;
14 end WHILE;
15 end;
2 create procedure set_rank()
3 begin
4 set @i=1;
5 set @number=(select count(1) from suppliers_performance);
6 update suppliers_performance set score_rank=0;
7
8 while @i<@number
9 do
10 begin
11 update suppliers_performance set score_rank=@i where id in (select id from (select id from suppliers_performance where score_rank=0 order by score limit 1) b);
12 set @i=@i+1;
13 end;
14 end WHILE;
15 end;
相关阅读 更多 +