我使用存儲過程來優化我的sql腳本的查詢。這是一個腳本來更新我的數據庫時,我執行它的表我沒有錯誤在同一時間,我沒有結果。我怎樣才能返回我的存儲過程的值?我的存儲過程的返回值
這裏是我的腳本:
DELIMITER |
CREATE PROCEDURE data_table1_test()
BEGIN
DROP TEMPORARY TABLE IF EXISTS ch.table1;
CREATE TEMPORARY TABLE ch.table1
SELECT STRAIGHT_JOIN
SOITAB.champ1 as champ1,
CONCAT(SOITAB.champ1,' ',SOITAB.fk_champcam) as champ1_cam,SOITAB.champup as champup,
supM(CASE WHEN (SOITAB.fk_champsois IN (8,11,12,14,18,19,20,47,51)) THEN 1 ELSE 0 END)/COUNT(DISTINCT CSSTAB.champicss) as champqtr,
supM(CASE WHEN (SOITAB.fk_champsois In (2,3,4,5,6,7,8,11,12,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,47,51))
THEN 1 ELSE 0 END)/COUNT(DISTINCT CSSTAB.champicss) as champqtn,
CTAB.champidcam as champidcam,
CTAB.champna as champna,
CTAB.champuk as champuk,
CTAB.champst as champst,
CTAB.champet as champet,
CTAB.champiden as champiden,
CTAB.champdeba as champdeba,
CSTAB.champids as champids,
CSTAB.champcat as champcat,
CSTAB.champop as champop,
CSTAB.champshco as champshco,
CSTAB.champxc as champxc,
LEFT(CSTAB.champxc,2) as champscon,
CSTAB.champdowe as champdowe,
CSTAB.fk_caogst as sht,
CSTAB.pr as pr,
CCTAB.champidcc as champidcc,
CCTAB.champna as p_champna,
CCTAB.champdes as pchampdes,
CCTAB.fk_ca_br,
MAX(LEFT(CCTAB.note,3)) AS bu,
GROUP_CONCAT(champspn, ' by ',FORMAT(CSSTAB.qu,0) ORDER BY champspn ASC SEPARATOR ' + ') as sup_champ1,
supm(distinct(CSSTAB.npp*CSSTAB.qu)) AS champpfi,
CsupTAB.champna as sup_champna,
CsupTAB.id_champcsu as sup_id,
CsupTAB.champiden as sup_champiden,
CCDTAB.champidcc as champidcc,
CCDTAB.ct1 as pct1,
CCDTAB.ct2 as pct2,
COUNT(distinct CSSTAB.champicss) as champseti,ch.PVGTAB.pv as pv,
supm(distinct(CSSTAB.npp*CSSTAB.qu)) AS npp,CHCTAB.p as p,
max(SOITAB.champcat) as lod
FROM bdata.champsoit SOITAB
LEFT OUTER JOIN bdata.champcsi CSTAB ON CSTAB.champ1 = SOITAB.champ1
LEFT OUTER JOIN bdata.champcam CTAB ON SOITAB.fk_champcam = CTAB.champidcam
LEFT OUTER JOIN bdata.champcsi_set CSSTAB ON CSSTAB.fk_champcsi = CSTAB.champids
LEFT OUTER JOIN bdata.champccco CCTAB ON CSTAB.fk_champccco = CCTAB.champidcc
LEFT OUTER JOIN bdata.champcccohcca CCHCTAB ON CCTAB.champidcc = CCHCTAB.fk_champccco
LEFT OUTER JOIN ch.champccde CCDTAB ON CCHCTAB.fk_c_cat= ch.CCDTAB.champidcc
LEFT OUTER JOIN bdata.champcamhch CHCTAB ON CHCTAB.fk_champccco = CCTAB.champidcc
LEFT OUTER JOIN ch.champpv PVGTAB on ch.PVGTAB.url = CCTAB.champidcc
LEFT OUTER JOIN bdata.champcsu CsupTAB ON CCTAB.fk_champcsu = CsupTAB.id_champcsu
WHERE CSTAB.champstat = 'active' AND CCTAB.champetap = 1 AND CCHCTAB.is_primary = '1'
GROUP BY SOITAB.champ1,SOITAB.fk_champcam;
END |
DELIMITER;
#####################champpgrte###############################################
DELIMITER |
CREATE PROCEDURE data_table2_test()
BEGIN
DROP TEMPORARY TABLE IF EXISTS ch.table2;
CREATE TEMPORARY TABLE ch.table2
SELECT STRAIGHT_JOIN
champspete.champ1,
supM(champspete.champqtn) as champqtn ,
supM(champspete.champqtr) as champqtr,
count(distinct champspete.campaign_id) as champscam,
champspete.sup_champna,
champspete.lod
FROM ch.champspete
GROUP BY ch.champspete.champ1;
ALTER TABLE ch.champpgrte ADD INDEX (champ1);
END |
DELIMITER ;
嗯,其實你不進行任何選擇。您正在使用select語句中的數據創建臨時表。而已。 – fancyPants
首先,謝謝你的回答,我想更新我的數據庫,我不知道我應該寫什麼來返回我的程序的值。 – Hacer