bitscn.com
mysql存储过程例子,不能在if else里面用begin end否则会报错error code:1064解决
error code : 1064
you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near
报错是因为mysql的procedure里面if else语句里面, 用了begin end语句,去掉了就ok了.
[sql]
delimiter $$
use `sportgbmj`$$
drop procedure if exists `sp_web_addmiddayrank`$$
create definer=`root`@`%` procedure `sp_web_addmiddayrank`()
begin
/*
修订记录:
-------------------------------------------------------------------
版本 修订人 修订日期 修订描述
-------------------------------------------------------------------
1.0.0 2013-06-15 查询当前中午12:30-13:30比赛排名
该sp 当前比赛结束后执行
排名先决条件:
1:在一场内必须完满10(含)局以上
-------------------------------------------------------------------
*/
declare i_date date ;
declare i_starttime time;
declare i_endtime time;
set i_date = now();
set i_endtime = now();
if (i_endtime > '22:30') then
begin
/* 夜间赛场 */
set i_starttime = '21:30';
set i_endtime = '22:30';
end
else
begin
/* 中午场 */
set i_starttime = '12:30';
set i_endtime = '13:30';
end
end if;
create temporary table tmp_rank(
id int not null auto_increment -- 自增
,userid int -- 用户标识
,beans int -- bean 汇总
,rounds tinyint -- 局数 汇总
,posttime time -- 时间 (该玩家本场比赛最后的时间)
) engine = myisam;
insert into tmp_rank (userid,beans,rounds,posttime)
select
userid
,sum(case when consume > 0 then consume else 0 end) beans
,count(userid) rounds
,max(posttime) as posttime
from
score as s
inner join
scorelist as sl
on
s.pid = sl.pid
where
roomid in ('1001') and (postdate = i_date and posttime >='12:30:00' and posttime
group by
userid
having
(rounds >= 10)
order by
beans desc
,maxtime asc
limit 500;
/*
插入排名表
*/
insert into
hf_playranklist (userid,rank,beans,rounds,postdate,posttime)
select
userid,beans,rounds,i_date,posttime
from tmp_rank;
/*
插入奖品表
*/
insert into hf_prizelist (userid,status,prizeid,receivetime,postdate)
select
userid
,0
,(case when id >= 11 then 4
when (id >= 3 and id
when id = 2 then 2
when id = 1 then 1
end) as prizeid
,beans
,rounds
,posttime
from
tmp_rank as r
where
rank >= 30;
end$$
delimiter ;
bitscn.com