1

我的视图将每个计数的结果输出为一列。我需要重组下面的代码,以便将每个计数输出为一行:一列标识计数,一列标识计数结果。任何帮助将不胜感激。

CREATE OR REPLACE VIEW oa_count_ii
AS
SELECT COUNT(
CASE
WHEN cap_udfi IN ('NEW_ENT','IRP_RVW')
AND mhd_mscc   = 'ADMUHFLSCP'
THEN 1
END ) newapp_admuhflscp,
COUNT(
CASE
WHEN cap_udfi IN   ('APF_RVW','RVW_RVW','TUT_RVW','TU2_RVW','TUT_DC1','TU2_DC1','RVW_IRP','IRP_IIO','IRP_DC1','IIO_DC1','RECALL')
AND cap_dec1   = 'No Decision'
AND mhd_mscc   = 'ADMUHFLSCP'
AND mhd_tsks   = 'P'
THEN 1
END ) apfrvw_admuhflscp,
COUNT(
CASE
WHEN cap_udfi IN ('RVW_TUT','TUT_TU2')
AND mhd_mscc  IN ('FACPSYCHL1','FACPSYCHL2')
AND mhd_tsks   ='T'
THEN 1
END ) rvwtutw_admuhflscp,
FROM oa_intray;
4

1 回答 1

1

由于这三个计数似乎完全相互排斥,您可以这样做:

CREATE OR REPLACE VIEW oa_count_ii AS
SELECT dl.count_type, count(ilv.count_type) record_count from
(SELECT CASE level
            WHEN 1 THEN 'newapp_admuhflscp'
            WHEN 2 THEN 'apfrvw_admuhflscp'
            WHEN 3 THEN 'rvwtutw_admuhflscp'
        END count_type
 FROM DUAL
 CONNECT BY level <= 3) dl
LEFT JOIN
(SELECT CASE
            WHEN cap_udfi IN ('NEW_ENT','IRP_RVW')
             AND mhd_mscc   = 'ADMUHFLSCP'
                THEN 'newapp_admuhflscp'
            WHEN cap_udfi IN   ('APF_RVW','RVW_RVW','TUT_RVW','TU2_RVW','TUT_DC1','TU2_DC1','RVW_IRP','IRP_IIO','IRP_DC1','IIO_DC1','RECALL')
             AND cap_dec1   = 'No Decision'
             AND mhd_mscc   = 'ADMUHFLSCP'
             AND mhd_tsks   = 'P'
                THEN 'apfrvw_admuhflscp'
            WHEN cap_udfi IN ('RVW_TUT','TUT_TU2')
             AND mhd_mscc  IN ('FACPSYCHL1','FACPSYCHL2')
             AND mhd_tsks   ='T'
                THEN 'rvwtutw_admuhflscp'
        END count_type
 FROM oa_intray) ilv
ON dl.count_type = ilv.count_type
GROUP BY dl.count_type;
于 2013-07-22T12:56:11.223 回答