2017-06-30 70 views
0

我有以下數據運行總和內的另一個

IdSource  20170629 20170628 20170626  20170625  20170624 20170623 
Id1.   OK   KO   N/A   KO   OK   KO 

我要算天數,我的數據(工作流的狀態)是KO的報告。不適用意味着不希望產生流量,因此不應計算在內。

預期結果:

IdSource  20170629 20170628 20170626  20170625 20170624  20170623 
Id1.   OK   KO(2)   N/A   KO(1)   OK  KO(1) 

計數必須在每個OK復位。

在SQL中,我會做

select t.*, 
     sum(case when status = 'KO' then 1 else 0 end) over (partition by id, cume_ko order by date) as nbDayKO 
from (select t.*, 
      sum(case when status = 'OK' then 1 else 0 end) over (partition by id order by date) as cume_ko 
     from t 
    ) t 

我試圖用運行總和函數沒有成功:

  • 我需要逆排序上
  • 我不能使用結果的日期在另一個runningSum的。

感謝您的幫助

回答

0

它的醜陋,不是很有效,但我沒有發現任何其他的解決方案。以下是我如何做到的:

If ([status] = 0) Then 0 
Else (

(If (RelativeValue([status];([dayOfWeek]);1) = 1) Then 
    If (RelativeValue([status];([dayOfWeek]);2) = 1) Then 
     If (RelativeValue([status];([dayOfWeek]);3) = 1) Then 
      If (RelativeValue([status];([dayOfWeek]);4) = 1) Then 
       If (RelativeValue([status];([dayOfWeek]);5) = 1) Then 
        If (RelativeValue([status];([dayOfWeek]);6) = 1) Then 
         If (RelativeValue([status];([dayOfWeek]);7) = 1) Then 
          If (RelativeValue([status];([dayOfWeek]);8) = 1) Then 
           If (RelativeValue([status];([dayOfWeek]);9) = 1) Then 
            If (RelativeValue([status];([dayOfWeek]);10) = 1) Then 
             If (RelativeValue([status];([dayOfWeek]);11) = 1) Then 
              If (RelativeValue([status];([dayOfWeek]);12) = 1) Then 
               If (RelativeValue([status];([dayOfWeek]);13) = 1) Then 
                If (RelativeValue([status];([dayOfWeek]);14) = 1) Then 
                 If (RelativeValue([status];([dayOfWeek]);15) = 1) Then 15 
                 Else 14 
                Else 13 
               Else 12 
              Else 11 
             Else 10 
            Else 9 
           Else 8 
          Else 7 
         Else 6 
        Else 5 
       Else 4 
      Else 3 
     Else 2 
    Else 1 
Else 0)+[status]) 
相關問題