12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-11-28 13:26:30
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
简单到网上搜了一下,没有发现mysql有类似oracle 的decode函数实现行转列,有不少用过程实现动态行转列,试了一下,不适合我用,参考mysql5的帮助,写个个过程,记录备忘。其中用到了游标
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
简单到网上搜了一下,没有发现mysql有类似oracle 的decode函数实现行转列,有不少用过程实现动态行转列,试了一下,不适合我用,参考mysql5的帮助,写个个过程,记录备忘。其中用到了游标,关于游标的使用文档里给的例子也不错,反正我就只会那么用。。。
DELIMITER $$
DROP PROCEDURE IF EXISTS `hrb_yd`.`proc_hrb_yd_stat`$$
CREATE DEFINER=`root`@`192.168.96.1` PROCEDURE `proc_hrb_yd_stat`(IN $G_id INTEGER(10))
BEGIN
declare v_name VARCHAR(255);
declare v INT DEFAULT 0;
declare v1 INT DEFAULT 0;
declare v2 INT DEFAULT 0;
declare v3 INT DEFAULT 0;
declare v4 INT DEFAULT 0;
declare v5 INT DEFAULT 0;
declare v6 INT DEFAULT 0;
declare a int ;
declare b varchar(255);
DECLARE done INT DEFAULT 0;
declare cur1 cursor for select id,name from hrb_yd_admin where g_id=$G_id ;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
select count(id) into v from hrb_yd_admin where g_id=$G_id;
open cur1;
repeat
fetch cur1 into a,b;
if not done then
select count(id) into v1 from hrb_yd_visit_table where user_id=a and visit_way='实地走访' ; /*实地走访次数*/
select count(id) into v2 from hrb_yd_visit_table where user_id=a and visit_way='电话' ;/*--电话拜访方式次数*/
select count(id) into v3 from hrb_yd_visit_table where user_id=a and visit_way='E—mail' ; /*--emianl拜访方式次数*/
select count(id) into v4 from hrb_yd_visit_table where user_id=a and visit_way ='' ;/*--其他拜访方式次数*/
select count(id) into v5 from hrb_yd_visit_table where user_id=a and visit_un_purpose='是'; /*--推荐成功数*/
select count(id) into v6 from hrb_yd_visit_table where user_id=a and visit_un_purpose='否'; /*--未推荐成功数*/
select b,v1,v2,v3,v4,v5,v6;
end if;
until done end repeat;
close cur1;
END$$
DELIMITER ;
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19