`
- 浏览:
35099 次
-
- DELIMITER $
-
- DROP PROCEDURE IF EXISTS `stat` $
- CREATE DEFINER=`liulive`@`%` PROCEDURE `stat`(startDate VARCHAR(14), endDate VARCHAR(14))
- BEGIN
- DECLARE total INT DEFAULT 0;
- DECLARE dat DATE DEFAULT NULL;
- DECLARE quals INT DEFAULT 0;
- DECLARE scheds INT DEFAULT 0;
- DECLARE shows INT DEFAULT 0;
- DECLARE kepts INT DEFAULT 0;
- DECLARE accepts INT DEFAULT 0;
- DECLARE _time VARCHAR(14) DEFAULT NULL;
- DECLARE assess VARCHAR(40) DEFAULT NULL;
-
- DECLARE offic VARCHAR(60) DEFAULT NULL;
- DECLARE recrui VARCHAR(60) DEFAULT NULL;
- DECLARE ma VARCHAR(60) DEFAULT NULL;
-
- DECLARE CNT INT DEFAULT 0;
-
- DECLARE _cursor_flag TINYINT(1) DEFAULT 0;
- /*定义光标*/
- DECLARE totalCalls CURSOR FOR Select count(flow_step) as total, DATE(operate_date) as dat, office, recruit, main from v_student where DATE(operate_date) >= DATE(startDate) And DATE(operate_date) <= DATE(endDate) group by DATE(operate_date), office, recruit, main order by DATE(operate_date);
- DECLARE qualCalls CURSOR FOR Select count(flow_step) as qual, DATE(operate_date) as dat, office, recruit, main from v_student where flow_step <> 'NQ' And DATE(operate_date) >= DATE(startDate) and DATE(operate_date) <= DATE(endDate) group by DATE(operate_date), office, recruit, main order by DATE(operate_date);
- DECLARE schedCalls CURSOR FOR Select count(flow_step) as sched, DATE(operate_date) as dat, office, recruit, main from v_student where flow_step = 'Assessment Scheduled' And DATE(operate_date) >= DATE(startDate) and DATE(operate_date) <= DATE(endDate) group by DATE(operate_date), office, recruit, main order by DATE(operate_date);
-
- DECLARE totalSched CURSOR FOR Select count(flow_step) as sched, officeTime, DATE(vco_date) as dat, assessor, office, recruit, main from v_student where flow_step = 'Assessment Scheduled' And DATE(vco_date) >= DATE(startDate) And DATE(vco_date) <= DATE(endDate) group by officeTime, DATE(vco_date), assessor, office, main order by DATE(vco_date);
- DECLARE showSched CURSOR FOR Select count(shows) as shows, officeTime, DATE(vco_date) as dat, assessor, office, recruit, main from v_student where shows is not null And flow_step = 'Assessment Scheduled' And DATE(vco_date) >= DATE(startDate) And DATE(vco_date) <= DATE(endDate) group by officeTime, DATE(vco_date), assessor, office, main order by DATE(vco_date);
- DECLARE qualSched CURSOR FOR Select count(qual) as quals, officeTime, DATE(vco_date) as dat, assessor, office, recruit, main from v_student where qual is not null And flow_step = 'Assessment Scheduled' And DATE(vco_date) >= DATE(startDate) And DATE(vco_date) <= DATE(endDate) group by officeTime, DATE(vco_date), assessor, office, main order by DATE(vco_date);
- DECLARE keptSched CURSOR FOR Select count(kept) as kepts, officeTime, DATE(vco_date) as dat, assessor, office, recruit, main from v_student where kept is not null And flow_step = 'Assessment Scheduled' And DATE(vco_date) >= DATE(startDate) And DATE(vco_date) <= DATE(endDate) group by officeTime, DATE(vco_date), assessor, office, main order by DATE(vco_date);
- DECLARE acceptSched CURSOR FOR Select count(accept) as accepts, officeTime, DATE(vco_date) as dat, assessor, office, recruit, main from v_student where accept is not null And flow_step = 'Assessment Scheduled' And DATE(vco_date) >= DATE(startDate) And DATE(vco_date) <= DATE(endDate) group by officeTime, DATE(vco_date), assessor, office, main order by DATE(vco_date);
- nbsp;
- /* 定义光标结束标志 */
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET _cursor_flag = -1;
-
- DELETE FROM STAT_TEMP;
- COMMIT;
-
- OPEN totalCalls; /*打开光标*/
- LOOP_totalCalls:LOOP /* 循环声明 */
- FETCH totalCalls INTO total, dat, offic, recrui, ma;
- IF _cursor_flag = -1 then
- LEAVE LOOP_totalCalls;
- END IF;
- insert into STAT_TEMP(DATE_, TOTAL_CALLS, OFFICE, RECRUIT, MAIN) values(dat, total, offic, recrui, ma);
- END LOOP;
- COMMIT;
- CLOSE totalCalls; /* 关闭光标 */
- SET _cursor_flag = 1; /* 重置光标结束标志 */
-
- OPEN qualCalls;
- LOOP_qualCalls:LOOP
- FETCH qualCalls INTO quals, dat, offic, recrui, ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_qualCalls;
- end if;
- SELECT COUNT(*) INTO CNT FROM STAT_TEMP WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma;
- IF CNT > 0 THEN
- UPDATE STAT_TEMP SET QUAL_CALLS=quals WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma;
- SET CNT = 0;
- ELSE
- insert into STAT_TEMP (DATE_, QUAL_CALLS, OFFICE, RECRUIT, MAIN) values(dat, quals, offic, recrui, ma);
- END IF;
- END LOOP;
- COMMIT;
- CLOSE qualCalls;
- SET _cursor_flag = 1;
-
- OPEN schedCalls;
- LOOP_schedCalls:LOOP
- FETCH schedCalls INTO scheds,dat,offic,recrui,ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_schedCalls;
- end if;
- SELECT COUNT(*) INTO CNT FROM STAT_TEMP WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma;
- IF CNT > 0 THEN
- UPDATE STAT_TEMP SET SCHED_CALLS=scheds WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma;
- SET CNT = 0;
- ELSE
- insert into STAT_TEMP(DATE_, SCHED_CALLS, OFFICE, RECRUIT, MAIN) values(dat, scheds, offic, recrui, ma);
- END IF;
- END LOOP;
- COMMIT;
- CLOSE schedCalls;
- SET _cursor_flag = 1;
-
- OPEN totalSched;
- LOOP_totalSched:LOOP
- FETCH totalSched INTO scheds, _time, dat, assess, offic, recrui, ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_totalSched;
- end if;
- select count(*) into CNT from STAT_TEMP where DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- if CNT > 0 then
- update STAT_TEMP set SCHED=scheds WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- SET CNT = 0;
- else
- insert into STAT_TEMP(DATE_, SCHED, ASSESSOR, OFFICE, RECRUIT, MAIN) values(dat, scheds, assess, offic, recrui, ma);
- end if;
- END LOOP;
- COMMIT;
- CLOSE totalSched;
- SET _cursor_flag = 1;
-
- OPEN showSched;
- LOOP_showSched:LOOP
- FETCH showSched INTO shows, _time, dat, assess,offic,recrui,ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_showSched;
- end if;
- select count(*) into CNT from STAT_TEMP where DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- if CNT > 0 then
- update STAT_TEMP set SHOWS=shows WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- SET CNT = 0;
- else
- insert into STAT_TEMP(DATE_, SHOWS, ASSESSOR, OFFICE, RECRUIT, MAIN) values(dat, scheds, assess, offic, recrui, ma);
- end if;
- END LOOP;
- COMMIT;
- CLOSE showSched;
- SET _cursor_flag = 1;
-
- OPEN qualSched;
- LOOP_qualSched:LOOP
- FETCH qualSched INTO quals, _time, dat, assess,offic,recrui,ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_qualSched;
- end if;
- select count(*) into CNT from STAT_TEMP where DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- if CNT > 0 then
- update STAT_TEMP set QUAL=quals WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- SET CNT = 0;
- else
- insert into STAT_TEMP(DATE_, QUAL, ASSESSOR, OFFICE, RECRUIT, MAIN) values(dat, quals, assess, offic, recrui, ma);
- end if;
- END LOOP;
- COMMIT;
- CLOSE qualSched;
- SET _cursor_flag = 1;
-
- OPEN keptSched;
- LOOP_keptSched:LOOP
- FETCH keptSched INTO kepts, _time, dat, assess, offic, recrui, ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_keptSched;
- end if;
- select count(*) into CNT from STAT_TEMP where DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- if CNT > 0 then
- update STAT_TEMP set KEPT=kepts WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- SET CNT = 0;
- else
- insert into STAT_TEMP(DATE_, KEPT, ASSESSOR, OFFICE, RECRUIT, MAIN) values(dat, kepts, assess, offic, recrui, ma);
- end if;
- END LOOP;
- COMMIT;
- CLOSE keptSched;
- SET _cursor_flag = 1;
-
- OPEN acceptSched;
- LOOP_acceptSched:LOOP
- FETCH acceptSched INTO kepts, _time, dat, assess, offic, recrui, ma;
- if _cursor_flag = -1 then
- LEAVE LOOP_acceptSched;
- end if;
- select count(*) into CNT from STAT_TEMP where DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- if CNT > 0 then
- update STAT_TEMP set KEPT=kepts WHERE DATE_ = dat And OFFICE = offic And RECRUIT = recrui And MAIN = ma And ASSESSOR=assess;
- SET CNT = 0;
- else
- insert into STAT_TEMP(DATE_, KEPT, ASSESSOR, OFFICE, RECRUIT, MAIN) values(dat, kepts, assess, offic, recrui, ma);
- end if;
- END LOOP;
- COMMIT;
- CLOSE acceptSched;
- END $
-
- DELIMITER ;
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
MySQL 存储过程实例 MySQL 存储过程实例详细介绍了 MySQL 存储过程的开发步骤,本节将通过具体的实例讲解 PHP 是如何操纵 MySQL 存储过程的。 创建存储过程 存储过程的创建是 MySQL 存储过程的基础,MySQL 5.0 ...
### MySQL存储过程实例教程 #### 存储过程概念与优势 存储过程,作为数据库中一种预编译的SQL语句集合,旨在实现特定功能并存储于数据库内,用户仅需指定其名称及必要参数即可调用执行。这种设计极大地简化了...
MYSQL 存储过程 实例,要的自己下,分有点贵哦。
MySQL存储过程实例教程 MySQL存储过程是数据库存储的一个重要的功能,它允许控制数据的访问方式,提供了灵活的编程方式,提高了数据库的处理速度和灵活性。本教程将详细介绍 MySQL 存储过程的概念、优点、创建和...
mysql存储过程实例详解
根据给定的信息,我们可以深入探讨PHP与MySQL存储过程的相关知识点,包括如何在MySQL中使用`CONCAT`函数、创建存储过程以及如何通过PHP脚本来调用这些存储过程。 ### 使用 CONCAT 函数 #### 标题中的示例 ```sql ...
在这个实例中,我们看到一个名为`Sum_wage`的存储过程,它的主要目的是对`ProWage`表中的工资进行加薪操作。 首先,存储过程的创建使用了`CREATE PROCEDURE`语句,定义了一个名为`Sum_wage`的过程,并接受三个参数...
MySQL存储过程是数据库管理系统提供的一种高级程序设计语言,允许用户在数据库中封装一系列复杂的操作,以便重复使用。在MySQL 5.0及后续版本中,存储过程被引入,极大地提升了数据库管理和应用程序的效率。本教程将...
### MySQL存储过程详解 #### 一、存储过程概述 存储过程是一种特殊类型的SQL代码集合,它们预先被编译并存储在数据库服务器上。用户可以通过指定存储过程名称并提供必要的参数来执行这些存储过程。这种机制提供了...
### PHP调用MySQL存储过程实例 在PHP中调用MySQL存储过程,通常使用`mysqli`扩展。在创建了存储过程后,我们可以通过PHP脚本来调用这些存储过程。以下是一个获取MySQL当前版本号的存储过程调用实例: ```sql ...
本资源结合实例实现一个复杂的存储过程,存储过程中有用到游标、临时表、循环、递归等知识,sql文件附有实例数据表创建的sql语句。
本实例展示了如何在MySQL存储过程中实现异常处理,以捕获并处理可能出现的错误。 首先,我们注意到在创建存储过程`myProc`时,使用了`delimiter $$`来改变MySQL客户端的语句分隔符,这是为了在存储过程中使用多个...
本文实例讲述了mysql存储过程之错误处理。分享给大家供大家参考,具体如下: 当存储过程中发生错误时,重要的是适当处理它,例如:继续或退出当前代码块的执行,并发出有意义的错误消息。其中mysql提供了一种简单的...