0

表示したい出力は、合計 EMPL_NUM のアキュムレータでした。たとえば、値はフィールド TOTAL_FEBRUARY=TOTAL_JANUARY+TOTAL_FEBRUARY に表示されますが、値はフィールド TOTAL_MARCH=TOTAL_MARCH+TOTAL_JANUARY+TOTAL_FEBRUARY に存在します。あなたの何人かがそれを行うための解決策を提供できることを願っています. どうもありがとうございました。コーディングは次のように表示されます。

SELECT 
(CASE WHEN To_Char(A.EFFDT,'MM')=01 THEN 1  
  WHEN To_Char(A.EFFDT,'MM')=02 THEN 2
  WHEN To_Char(A.EFFDT,'MM')=03 THEN 3
  WHEN To_Char(A.EFFDT,'MM')=04 THEN 4
  WHEN To_Char(A.EFFDT,'MM')=05 THEN 5
  WHEN To_Char(A.EFFDT,'MM')=06 THEN 6
  WHEN To_Char(A.EFFDT,'MM')=07 THEN 7
  WHEN To_Char(A.EFFDT,'MM')=08 THEN 8
  WHEN To_Char(A.EFFDT,'MM')=09 THEN 9
  WHEN To_Char(A.EFFDT,'MM')=10 THEN 10
  WHEN To_Char(A.EFFDT,'MM')=11 THEN 11
  WHEN To_Char(A.EFFDT,'MM')=12 THEN 12
  ELSE NULL END) AS MONTHS 

  ,Count(*) AS EMPL_NUM

  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=01 THEN 1 ELSE 0 END) AS TOTAL_JANUARY 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=02 THEN 1 ELSE 0 END) AS TOTAL_FEBRUARY 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=03 THEN 1 ELSE 0 END) AS TOTAL_MARCH 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=04 THEN 1 ELSE 0 END) AS TOTAL_APRIL  
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=05 THEN 1 ELSE 0 END) AS TOTAL_MAY 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=06 THEN 1 ELSE 0 END) AS TOTAL_JUN 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=07 THEN 1 ELSE 0 END) AS TOTAL_JULY  
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=08 THEN 1 ELSE 0 END) AS TOTAL_AUGUST 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=09 THEN 1 ELSE 0 END) AS TOTAL_SEPTEMBER 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=10 THEN 1 ELSE 0 END) AS TOTAL_OCTOBER
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=11 THEN 1 ELSE 0 END) AS TOTAL_NOVEMBER 
  ,Sum(CASE WHEN To_Char(A.EFFDT,'MM')=12 THEN 1 ELSE 0 END) AS TOTAL_DECEMBER 

  FROM PS_JOB A
 ,PS_CITIZEN_PSSPRT B
 ,PS_CITIZENSHIP C
 ,PS_CITIZEN_STS_TBL D

 WHERE A.HR_STATUS='A'

 AND A.EFFDT=(SELECT Max(A1.EFFDT) FROM PS_JOB A1 WHERE A.EMPLID=A1.EMPLID AND A.EMPL_RCD=A1.EMPL_RCD AND A1.EFFDT<=SYSDATE)

 AND A.EMPL_RCD=0

 AND A.EFFSEQ=(SELECT Max(A2.EFFSEQ) FROM PS_JOB A2 WHERE A.EMPLID=A2.EMPLID AND A.EMPL_RCD=A2.EMPL_RCD AND A.EFFDT=A2.EFFDT)

 AND A.EMPLID =B.EMPLID(+) 

 AND B.DEPENDENT_ID=' '

 AND A.EMPLID=C.EMPLID  

 AND B.EMPLID=C.EMPLID

 AND B.DEPENDENT_ID=C.DEPENDENT_ID

 AND B.COUNTRY=C.COUNTRY

 AND B.COUNTRY=D.COUNTRY                                    

 AND C.COUNTRY=D.COUNTRY

 AND C.CITIZENSHIP_STATUS=D.CITIZENSHIP_STATUS

 AND C.CITIZENSHIP_STATUS IN ('5','7') 

 AND To_Char(A.EFFDT,'YYYY')=2012

  GROUP BY CASE WHEN To_Char(A.EFFDT,'MM')=01 THEN 1  
  WHEN To_Char(A.EFFDT,'MM')=02 THEN 2
  WHEN To_Char(A.EFFDT,'MM')=03 THEN 3
  WHEN To_Char(A.EFFDT,'MM')=04 THEN 4
  WHEN To_Char(A.EFFDT,'MM')=05 THEN 5
  WHEN To_Char(A.EFFDT,'MM')=06 THEN 6
  WHEN To_Char(A.EFFDT,'MM')=07 THEN 7
  WHEN To_Char(A.EFFDT,'MM')=08 THEN 8
  WHEN To_Char(A.EFFDT,'MM')=09 THEN 9
  WHEN To_Char(A.EFFDT,'MM')=10 THEN 10
  WHEN To_Char(A.EFFDT,'MM')=11 THEN 11
  WHEN To_Char(A.EFFDT,'MM')=12 THEN 12
  ELSE NULL END 

ここにインターコード

4

2 に答える 2

2

SUM を計算するときは <= 演算子を使用します。例:

Sum(CASE WHEN TO_NUMBER(To_Char(A.EFFDT,'MM')) <= 3 THEN 1 ELSE 0 END) AS TOTAL_MARCH
于 2012-12-05T03:36:00.977 に答える
1

あなたが求めているのは現在の合計だと思います。分析関数を見てみましょう (たとえば、psougサイト)。クエリのコアが正しい場合は、内側のクエリで通常の集計を行い、それを分析関数にラップして現在の合計を求めます。

SELECT month
      ,SUM(month_count) OVER ( ROWS BETWEEN UNBOUNDED PRECEDING
                                        AND CURRENT ROW )
       AS running_total

FROM (  SELECT To_Char(A.EFFDT,'MM') AS month
              ,COUNT(*) AS month_count

          FROM PS_JOB A
              ,PS_CITIZEN_PSSPRT B
              ,PS_CITIZENSHIP C
              ,PS_CITIZEN_STS_TBL D

          WHERE A.HR_STATUS='A'

            AND A.EFFDT=( SELECT Max(A1.EFFDT)
                            FROM PS_JOB A1 
                            WHERE A.EMPLID=A1.EMPLID
                              AND A.EMPL_RCD=A1.EMPL_RCD
                              AND A1.EFFDT<=SYSDATE )

            AND A.EMPL_RCD=0

            AND A.EFFSEQ=( SELECT Max(A2.EFFSEQ)
                             FROM PS_JOB A2
                             WHERE A.EMPLID=A2.EMPLID
                               AND A.EMPL_RCD=A2.EMPL_RCD
                               AND A.EFFDT=A2.EFFDT )

            AND A.EMPLID =B.EMPLID(+) 

            AND B.DEPENDENT_ID=' '

            AND A.EMPLID=C.EMPLID  

            AND B.EMPLID=C.EMPLID

            AND B.DEPENDENT_ID=C.DEPENDENT_ID

            AND B.COUNTRY=C.COUNTRY

            AND B.COUNTRY=D.COUNTRY                                    

            AND C.COUNTRY=D.COUNTRY

            AND C.CITIZENSHIP_STATUS=D.CITIZENSHIP_STATUS

            AND C.CITIZENSHIP_STATUS IN ('5','7') 

            AND To_Char(A.EFFDT,'YYYY')=2012

          GROUP BY To_Char(A.EFFDT,'MM')

     )

ORDER BY month
于 2012-12-05T03:33:11.247 に答える