SELECT
NVL(DTM, 'SUM') DTM
,COUNT(PKG_SNO) STUDENT_PKG
,COUNT((CASE WHEN SHAR_YN=1 THEN PKG_SNO END)) SHARED
,COUNT((CASE WHEN SHAR_YN=0 THEN PKG_SNO END)) NON_SHARED
FROM
/* Dates */
(SELECT
TO_CHAR (TO_DATE (#startDt#,'YYYY-MM-DD')+LEVEL- 1, 'YYYY.MM.DD') AS DAY
FROM DUAL
CONNECT BY TO_DATE(#startDt#, 'YYYY-MM-DD') + LEVEL - 1 <= TO_DATE(#endDt#, 'YYYY-MM-DD')
) DAY LEFT OUTER JOIN
(
SELECT
TO_CHAR(RGS_DTM, 'YYYY.MM.DD') DTM
,PKG_SNO
,SHAR_YN
FROM lrms.v_lrpm_pkg
WHERE
USE_YNDCD = 1
AND MNGT_PRDN_YN ='N'
AND PARN_PKG_SNO = 0
AND TO_CHAR(RGS_DTM, 'YYYY.MM.DD') BETWEEN #startDt# AND #endDt#
) PKG ON DAY.DAY = PKG.DTM
GROUP BY ROLLUP(DTM)
ORDER BY group by YEAR(yourdae),MONTH(yourdate)
質問する
221 次
2 に答える
1
私があなたの要件を理解している限り、毎月いくつかの列を集計する必要があります。これを使用できます:
更新 2:
SELECT TRUNC(RGS_DTM, 'MM'), COUNT(PKG_SNO) STUDENT_PKG_COUNT, COUNT(SHARED) SHARED_COUNT, COUNT(NON_SHARED) NON_SHARED_COUNT
FROM (SELECT PKG_SNO,
CASE WHEN SHAR_YN = 1 THEN PKG_SNO END SHARED,
CASE WHEN SHAR_YN = 0 THEN PKG_SNO ENDNON_SHARED
FROM lrms.v_lrpm_pkg
WHERE USE_YNDCD = 1
AND MNGT_PRDN_YN = 'N'
AND PARN_PKG_SNO = 0
AND TO_CHAR(RGS_DTM, 'YYYY.MM.DD') BETWEEN #startDt# AND #endDt#)
GROUP BY TRUNC(RGS_DTM, 'MM')
于 2013-07-02T08:52:05.410 に答える