mysql一些小事例

mysql一些小例子

在群里遇到有人问了个问题:其表结构如下:

他想要用SQL 如何更新 站号 列各出现的次数到 频次 列。(注:站号对应 name,频次对应 no)

最后用游标实现了他想的功能:

create procedure pro_hzcount()
     begin
     declare cur_no,y int;
     declare cur_name varchar(20);
     declare cursor_1 cursor for SELECT name,count(name) FROM t1 group by name; 
     declare continue handler for not found
     set y=1;
     open cursor_1;
     repeat
         fetch cursor_1 into cur_name,cur_no;
         update t1 set no=cur_no where name=cur_name;
     until y=1 end repeat;
     close cursor_1;
    end;
mysql一些小事例

相关文章:

你感兴趣的文章:

标签云: