mysql实现分组排序并赋予序号的存贮过程

时间:2021-06-10 09:50:29
 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 ;