CREATE TEMPORARY TABLE IF NOT EXISTS temp (Months VARCHAR(50),Sequence INT)
AS (
SELECT
CONCAT(MONTHNAME(m1),' ',YEAR(m1)) AS Months,CONVERT(m1,DATE) AS Sequence
FROM
(
SELECT
('2014-01-01' - INTERVAL DAYOFMONTH('2014-01-01')-1 DAY)
+INTERVAL m MONTH AS m1
FROM
(
SELECT @rownum:=@rownum+1 AS m FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t2,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t3,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t4,
(SELECT @rownum:=-1) t0
) d1
) d2
WHERE m1<= '2015-07-30'
ORDER BY m1
) ;
SELECT t.Months,A.OpenCount,A.CloseCount FROM Temp T
LEFT JOIN ( SELECT CONCAT(MONTHNAME(e.dtcdate),' ',YEAR(e.dtcdate)) AS Months,
( SELECT COUNT(csr.ddlcsstatus) FROM csrcrn_frmempengagreqs csr
JOIN master_detail md ON md.masterDetailId=csr.ddlcsstatus WHERE md.abbr='open' AND csr.dtcdate >='2014-01-01' AND csr.dtcdate <='2015-07-30' AND csr.ddlArea=e.ddlArea ) AS OpenCount
,
( SELECT COUNT(csr.ddlcsstatus) FROM csrcrn_frmempengagreqs csr
JOIN master_detail md ON md.masterDetailId=csr.ddlcsstatus WHERE md.abbr='Close' AND csr.dtcdate >='2014-01-01' AND csr.dtcdate <='2015-07-30' AND csr.ddlArea=e.ddlArea ) AS CloseCount
FROM csrcrn_frmempengagreqs e
INNER JOIN master_detail m ON e.ddlcsstatus=m.masterDetailId
WHERE e.dtcdate >='2014-01-01' AND e.dtcdate <='2015-07-30'
GROUP BY MONTH(e.dtcdate) ORDER BY e.dtcdate
) A ON CONVERT(A.Months,CHAR(20))=CONVERT(T.Months,CHAR(20))
ORDER BY T.Sequence;
DROP TEMPORARY TABLE IF EXISTS temp;
/ * 주어진 쿼리는 결과를 성공적으로 제공합니다 ...이 쿼리를 USP에 넣은 다음 오류 plz help me..proc가 표시되면 * /
DELIMITER $$
DROP PROCEDURE IF EXISTS `usp_GetEngMonthlyChart_Test`$$
CREATE DEFINER=`root`@`%` PROCEDURE `usp_GetEngMonthlyChart_Test`(IN DateFrom DATE,IN DateTo DATE)
BEGIN
-- SET @strWhere= CONCAT(' AND CSR.dtcInductionDate BETWEEN ''',CONVERT(DateFrom,DATE),''' AND ','''',CONVERT(DateTo,DATE),'''');
SET @strSql=CONCAT('
CREATE TEMPORARY TABLE IF NOT EXISTS temp (Months VARCHAR(50),Sequence INT)
AS (
SELECT
CONCAT(MONTHNAME(m1),'' '',YEAR(m1)) AS Months,CONVERT(m1,DATE) AS Sequence
FROM
(
SELECT
(''',DateFrom,''' - INTERVAL DAYOFMONTH(''',DateFrom,''')-1 DAY)
+INTERVAL m MONTH AS m1
FROM
(
SELECT @rownum:=@rownum+1 AS m FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t2,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t3,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) t4,
(SELECT @rownum:=-1) t0
) d1
) d2
WHERE m1<= ''',DateTo,'''
ORDER BY m1
)' );
SET @strSql=CONCAT(@strSql,'; GO SELECT t.Months,A.OpenCount,A.CloseCount FROM Temp T
LEFT JOIN ( SELECT CONCAT(MONTHNAME(e.dtcdate),'' '',YEAR(e.dtcdate)) AS Months,
( SELECT COUNT(csr.ddlcsstatus) FROM csrcrn_frmempengagreqs csr
JOIN master_detail md ON md.masterDetailId=csr.ddlcsstatus WHERE md.abbr=''open'' AND csr.dtcdate >=''',DateFrom,
''' AND csr.dtcdate <=''',DateTo,''' AND csr.ddlArea=e.ddlArea ) AS OpenCount
,
( SELECT COUNT(csr.ddlcsstatus) FROM csrcrn_frmempengagreqs csr
JOIN master_detail md ON md.masterDetailId=csr.ddlcsstatus WHERE md.abbr=''Close'' AND csr.dtcdate >=''',DateFrom,
''' AND csr.dtcdate <=''',DateTo,''' AND csr.ddlArea=e.ddlArea ) AS CloseCount
FROM csrcrn_frmempengagreqs e
INNER JOIN master_detail m ON e.ddlcsstatus=m.masterDetailId
WHERE e.dtcdate >=''',DateFrom,''' AND e.dtcdate <=''',DateTo,'''
GROUP BY MONTH(e.dtcdate) ORDER BY e.dtcdate
) A ON CONVERT(A.Months,CHAR(20))=CONVERT(T.Months,CHAR(20))
ORDER BY T.Sequence;
DROP TEMPORARY TABLE IF EXISTS temp;');
SELECT @strSql;
PREPARE stmt FROM @strSql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;
CALL usp_GetEngMonthlyChart_Test ( '2014-01-01', '2015-07-30')
DROP
하면 임시 MEMORY 를 명시 적으로 지정 해야 한다고 가정합니다 표. 내가 올바르게 가정합니까?