您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“mysql5中怎么在使用過程實(shí)現(xiàn)行轉(zhuǎn)列”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“mysql5中怎么在使用過程實(shí)現(xiàn)行轉(zhuǎn)列”吧!
簡(jiǎn)單到網(wǎng)上搜了一下,沒有發(fā)現(xiàn)mysql有類似oracle 的decode函數(shù)實(shí)現(xiàn)行轉(zhuǎn)列,有不少用過程實(shí)現(xiàn)動(dòng)態(tài)行轉(zhuǎn)列,試了一下,不適合我用,參考mysql5的幫助,寫個(gè)個(gè)過程,記錄備忘。其中用到了游標(biāo),關(guān)于游標(biāo)的使用文檔里給的例子也不錯(cuò),反正我就只會(huì)那么用。。。
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='實(shí)地走訪' ; /*實(shí)地走訪次數(shù)*/
select count(id) into v2 from hrb_yd_visit_table where user_id=a and visit_way='電話' ; /*--電話拜訪方式次數(shù)*/
select count(id) into v3 from hrb_yd_visit_table where user_id=a and visit_way='E—mail' ; /*--emianl拜訪方式次數(shù)*/
select count(id) into v4 from hrb_yd_visit_table where user_id=a and visit_way ='' ; /*--其他拜訪方式次數(shù)*/
select count(id) into v5 from hrb_yd_visit_table where user_id=a and visit_un_purpose='是'; /*--推薦成功數(shù)*/
select count(id) into v6 from hrb_yd_visit_table where user_id=a and visit_un_purpose='否'; /*--未推薦成功數(shù)*/
select b,v1,v2,v3,v4,v5,v6;
end if;
until done end repeat;
close cur1;
END$$
DELIMITER ;
到此,相信大家對(duì)“mysql5中怎么在使用過程實(shí)現(xiàn)行轉(zhuǎn)列”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。