mysql一些小例子

在群里遇到有人问了个问题:其表结构如下:
[img]http://dl.iteye.com/upload/attachment/0064/2472/638cab42-4499-3249-9f1a-4aecefd73340.jpg[/img]
他想要用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;
:wink:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值