代码之家  ›  专栏  ›  技术社区  ›  Pam S.

从现有表迭代以创建另一个表-Qlikview

  •  1
  • Pam S.  · 技术社区  · 7 年前

    如果标题不够清楚,我很抱歉,但在Qlikview中可以这样做吗?

    Variable   Status   Date                    Duration (Hours)
    A          StatusA  9/10/2017 18:30:00.00   4
    A          StatusB  9/10/2017 23:30:00.00   5
    B          StatusA  9/10/2017 10:00:00.00   8
    B          StatusB  9/10/2017 21:45:00.00   9
    

    以及我希望它如何处理。

    Variable   Status   Date                    Duration (Hours)    FinishDate
    A          StatusA  9/10/2017 18:30:00.00   4                   9/10/2017 22:30:00.00
    A          StatusB  9/10/2017 23:30:00.00   0.5                 9/10/2017 23:59:59.59
    A          StatusB  9/11/2017 0:00:00.00    4.5                 9/11/2017 3:30:00.00
    B          StatusA  9/10/2017 10:00:00.00   8                   9/10/2017 18:00:00.00
    B          StatusB  9/10/2017 21:45:00.00   2.25                9/10/2017 23:59:59.59
    B          StatusB  9/11/2017 0:00:00.00    6.75                9/11/2017 6:15:00.00
    

    我知道这可以通过常驻表实现,但如何检查 变量的 运行时间超过一天,然后创建另一行以分隔到第二天的持续时间。这是因为我每周都有一个过滤器,所以如果最后一天(或周六)有 变量 如果超过持续时间,数据将不准确。

    结果数据将需要获得每个 变量

    脚本:

    T1:
    LOAD *, timestamp(Timestamp+[Duration Hours]/24) as FinishDate;
    LOAD *, timestamp(Timestamp#(left(Date,19),'DD-MM-YYYY hh:mm:ss')) as Timestamp;
    LOAD
        [EquipmentID] AS [Equipment ID],
        [TransactionDate] AS [Date],
        [LotID] AS [Lot ID],
        [Status] AS [Status],
        [DurationHours] AS [Duration Hours];
    SQL 
        SELECT *
        FROM [SQL_SourceDB].[dbo].[SourceTable]
        WHERE [TransactionDate] >= '2016-01-01 00:00:00.000' AND [TransactionDate] <= '2016-01-31 00:00:00.000';
    
    Left Join // add a split-flag where needed
    LOAD Distinct Timestamp,FinishDate,fabs(Date(left(FinishDate,10))-Date(left(Timestamp,10)) >=1) as SplitFlag
    Resident T1;
    
    T2: // load first part (current day) of split-flag=1
    LOAD 
        [Equipment ID],
        [Timestamp] AS [Date],
        [Lot ID],
        [Status],
        round((DayEnd(Timestamp)-Timestamp)*24,0.1) AS [Duration Hours]
    Resident T1
    Where SplitFlag=1;
    Concatenate // load second part (next day) where split-flag=1
    LOAD 
        [Equipment ID],
        daystart(FinishDate) AS [Date],
        [Lot ID],
        [Status],
        round((FinishDate-daystart(FinishDate))*24,0.1) AS [Duration Hours]
    Resident T1
    Where SplitFlag=1;
    Concatenate // add the rest of the data (split-flag=0)
    LOAD * Resident T1 Where SplitFlag=0;
    
    DROP Table T1;   
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   EldadT    7 年前

    这应该有效(请参阅代码中的注释):

    T1: // first need to set a proper timestamp and FinishDate
    Load *, timestamp(Timestamp+[Duration (Hours)]/24) as FinishDate;
    Load *, timestamp(Timestamp#(left(Date,19),'DD-MM-YYYY hh:mm:ss')) as Timestamp;
    LOAD * INLINE [
        Variable, Status, Date, Duration (Hours)
        A, StatusA, 10-09-2017 18:30:00.00, 4
        A, StatusB, 10-09-2017 23:30:00.00, 5
        B, StatusA, 10-09-2017 10:00:00.00, 8
        B, StatusB, 10-09-2017 21:45:00.00, 9
    ];
    
    left join // add a split-flag where needed
    Load Distinct Timestamp,FinishDate,fabs(Date(left(FinishDate,10))-Date(left(Timestamp,10)) >=1) as SplitFlag
    Resident T1;
    
    T2: // load first part (current day) of split-flag=1
    Load Variable,Status,
    	 Timestamp,
    	 dayEnd(Timestamp) as FinishDate,
    	 round((DayEnd(Timestamp)-Timestamp)*24,0.1) as [Duration (Hours)]
    Resident T1
    where SplitFlag=1;
    Concatenate // load second part (next day) where split-flag=1
    Load Variable,Status,
    	 daystart(FinishDate) as Timestamp,
    	 FinishDate,
    	 round((FinishDate-daystart(FinishDate))*24,0.1) as [Duration (Hours)]
    Resident T1
    where SplitFlag=1;
    Concatenate // add the rest of the data (split-flag=0)
    Load * Resident T1 Where SplitFlag=0;
    
    drop table T1;