Defining Stored Programs
ok
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN SET @w = 10 ; TRUNCATE rank_month ;
WHILE @w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
@w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (@w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET @w = @w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
ok
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN
TRUNCATE rank_month ;
SET @w = 10 ;
WHILE @w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
@w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (@w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET @w = @w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN
TRUNCATE rank_month ;
DECLARE w INT ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month;
[Err] 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 'DECLARE w INT ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk' at line 4
http://dev.mysql.com/doc/refman/5.7/en/stored-programs-defining.html
DROP PROCEDURE
IF EXISTS truncate_insert_rank_month;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_month ()
BEGIN DECLARE w INT ; TRUNCATE rank_month ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_month (
fk_country,
fk_categoryid,
topx,
history_year,
history_month,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%M') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_month; DROP PROCEDURE
IF EXISTS truncate_insert_rank_week;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_week ()
BEGIN DECLARE w INT ; TRUNCATE rank_week ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_week (
fk_country,
fk_categoryid,
topx,
history_year,
history_week,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%V'),
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid,
DATE_FORMAT(grab_date, '%Y'),
DATE_FORMAT(grab_date, '%V') ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER;
CALL truncate_insert_rank_week; DROP PROCEDURE
IF EXISTS truncate_insert_rank_all;
DELIMITER /w/ CREATE PROCEDURE truncate_insert_rank_all ()
BEGIN DECLARE w INT ; TRUNCATE rank_all ;
SET w = 10 ;
WHILE w < 110 DO
INSERT INTO rank_all (
fk_country,
fk_categoryid,
topx,
coin_sum,
amount_sum
) SELECT
country,
categoryid,
w,
SUM(grab_coin),
SUM(grab_amount)
FROM
grab_rank
WHERE
grab_amount_rank < (w + 1)
GROUP BY
country,
categoryid ;
SET w = w + 10 ;
END
WHILE ;
END/w/
DELIMITER ; CALL truncate_insert_rank_all;
Defining Stored Programs的更多相关文章
- Using Stored Programs with MySQLdb
http://flylib.com/books/en/1.142.1.125/1/ Using Stored Programs with MySQLdb The techniques for call ...
- MySQL之mysql命令使用详解
MySQL Name mysql - the MySQL command-line tool Synopsis mysql [options] db_name Description mysql is ...
- An Introduction to Stored Procedures in MySQL 5
https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...
- Migrating Oracle on UNIX to SQL Server on Windows
Appendices Published: April 27, 2005 On This Page Appendix A: SQL Server for Oracle Professionals Ap ...
- MySQL权限系统(二). MySQL提供的特权 Privileges Provided by MySQL
MySQL provides privileges that apply in different contexts and at different levels of operation: Adm ...
- MySQL 之 Metadata Locking 研究
MySQL5.5 中引入了 metadata lock. 顾名思义,metadata lock 不是为了保护表中的数据的,而是保护 database objects(元数据)的.包括表结构.schem ...
- My Sql 中要Alter Table的同学请注意!!!
首先我建议你在对MySQL表做DDL操作时: 1 执行 show processlist 查看,要操作的表(数据库对象)是否处于锁状态 if("未锁定") { 执行DDL语句 }e ...
- Raising Error Conditions with MySQL SIGNAL / RESIGNAL Statements
http://www.mysqltutorial.org/mysql-signal-resignal/ Summary: in this tutorial, you will learn how to ...
- [MySQL Reference Manual] 6 安全性
6. 安全性 在Mysql安装配置时要考虑安全性的影响,以下几点: Ÿ 常规因素影响安全性 Ÿ 程序自身安全性 Ÿ 数据库内部的安全性,即,访问控制 Ÿ 网络安全性和系统安全性 Ÿ ...
随机推荐
- Java程序员最常用的8个Java日志框架
转自:http://www.codeceo.com/article/8-java-log-framework.html 作为一名Java程序员,我们开发了很多Java应用程序,包括桌面应用.WEB应用 ...
- 解决 Agent admitted failure to sign using the key 问题 with ssh
之前如果建立 ssh 连接,只要將公鑰複製到 ~/.ssh/authorized_keys 就可以利用金鑰登入而不需要建立密碼. 現在的 ssh 使用同樣的方法會出現錯誤訊息 Agent admitt ...
- 重构实践——为了try-catch大兴排场
可能是我们共同的强迫症,不要说看到,就算想到太多的try-catch也很难接受. 于是,开始了一些尝试,这些尝试都算是思维的锻炼.场面的见识.经验的积累. Version1 —— 原始版本 一开始,在 ...
- ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- BZOJ1444 : [Jsoi2009]有趣的游戏
建立AC自动机,并求出转移矩阵. 再用$\sum E(终止节点)=1$去替换第一个方程,高斯消元即可. 时间复杂度$O(n^3l^3)$. 注意精度问题,要特判0.00的情况. #include< ...
- 匈牙利命名法——命名规范(知道这些再看Windows程序就轻松多了)
匈牙利命名法著名的命名规则当推Microsoft公司的"匈牙利"法,该命名规则的主要思想是"在变量和函数名中加入前缀以增进人们对程序的理解".例如所有的字符变量 ...
- COJ574 数字序列
试题描述 霸中智力测试机构的一项工作就是按照一定的规则删除一个序列的数字,得到一个确定的数列.陈思同学很渴望成为霸中智力测试机构的主管,但是他在这个工作上做的并不好,俗话说熟能生巧,他打算做很多练 ...
- 实现自己的Linq to Sql
之前写过一篇<统一的仓储接口>,为了方便使用不同的仓储.在我们的项目中使用的是EF4.0,但是这个版本的EF有一些性能问题没有解决,又不想升级到EF6,具体EF6有没有解决暂时不清楚.我们 ...
- 用Git进行协同开发
用Git进行协同开发 问题场景描述 常常会遇到这样的协同场景:后台的同事和前端的同事需要共同开发一个新功能,而他们的代码相互依赖,所以需要不停地更新各自的代码进行联调. 对于这种场景,最简单的方式就是 ...
- Notepad++ Shortcuts 快捷键
Ctrl-C Copy Ctrl-X Cut Ctrl-V Paste Ctrl-Z Undo Ctrl-Y Redo Ctrl-A Select All Ctrl-F L ...