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了.

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 <='13:30:00')
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 <= 10) THEN 3
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 ;

MySQL 存储过程例子,不能在if else里面用begin end否则会报错Error Code : 1064!的更多相关文章

  1. Mysql报错Error Code: 1175. You are using safe update

    使用MySQL执行update的时候报错:Error Code: 1175. You are using safe update mode and you tried to update a tabl ...

  2. CentOS命令登录MySQL时,报错ERROR 1045 (28000):

    CentOS命令登录MySQL时,报错ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)错误解 ...

  3. mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法

    1. 问题背景         InnoDB是新版MySQL(v5.5及以后)默认的存储引擎,之前版本的默认引擎为MyISAM,因此,低于5.5版本的mysql配置文件.my.cnf中,关于InnoD ...

  4. MySQL报错ERROR 1558 (HY000): Column count of mysql.user is wrong.

    MySQL报错ERROR 1558 (HY000): Column count of mysql.user is wrong. 1.今天在使用MySQL创建数据库时出现如下报错: mysql> ...

  5. 解决MySQL报错ERROR 2002 (HY000)【转】

    今天在为新的业务线搭架数据库后,在启动的时候报错 root@qsbilldatahis-db01:/usr/local/mysql/bin# ./mysql ERROR 2002 (HY000): C ...

  6. 第一次登录mysql,使用任何命令都报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    问题: 使用临时密码登录成功后,使用任何myql命令,例如show databases;都提示下面的报错 ERROR 1820 (HY000): You must reset your passwor ...

  7. MySQL查询报错 ERROR: No query specified

    今天1网友,查询报错ERROR: No query specified,随后它发来截图. root case:查询语法错误 \G后面不能再加分号;,由于\G在功能上等同于;,假设加了分号,那么就是;; ...

  8. 【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法

    step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer% ...

  9. 【mysql】 load local data infield 报错 ERROR 1148 (42000): The used command is not allowed with this MySQL version

    mysql> load data local infile '/Users/flint/learn/mysql/pet' into table bx_pet; 执行报错 ERROR 1148 ( ...

随机推荐

  1. Sublime 脚本 配置 (lua 和 JavaScript篇)

    { "cmd" :["C:/Lua/Lua.exe","$file"], "file_regex" :"^(? ...

  2. 蓝牙Profile的概念和常见种类

    蓝牙Profile Bluetooth的一个很重要特性,就是所有的Bluetooth产品都无须实现全部 的Bluetooth规范.为了更容易的保持Bluetooth设备之间的兼容,Bluetooth规 ...

  3. C# 课堂总结4-类(常用的类)

    一.string类 1. str.Length:字符串的长度 *****str[索引号] 2. str.Trim():去除左右两边的空格 *****str.TrimStart():去掉左边的空格str ...

  4. tomcat启动后ids页面无法访问

    修改servers-->tomcat6.0-->server.xml <Context docBase="/tds7030-web" path="&qu ...

  5. AlphaMobileControls介绍

    大家在开发wince程序或者windows mobile程序时还在为丑陋的界面着急吗?AlphaMobileControls可以帮你解决这些方案.当然如果你是高手可以自己去实现一些特殊的功能,自己定义 ...

  6. ORACLE客户端乱码

    sqlplus 打开CMD窗口,出现乱码情况的解决办法 C:\Documents and Settings>set NLS_LANG=american_america.AL32UTF8 C:\D ...

  7. C语言的system函数

     这个是与操作系统有关的函数,在linux/unix下system可以运行所有的shell命令windows下system可运行所有的windows执行文件,除DOS命令外,也可运行windwos ...

  8. NoSQL简要数据库

    前言 NoSQL:not only SQL(不No SQL啊),它的意思是:在关系数据库中使用关系数据库时适用,但在关系数据库中不适合本地使用其它数据库.NoSQL了弥补关系型数据库的不足,能够算是关 ...

  9. em换算px

    一般浏览器默认的1em=16px,所以常用字体大小如下: 10px=0.625em 12px=0.75em 14px=0.875em 16px=1em 18px=1.125em 20px=1.25em ...

  10. 双击GridView查看详情

    效果如下: protected void gvEquData_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowTy ...