Qlikview计算过去12小时内的所有产品

时间:2018-10-26 03:30:13

标签: sql qlikview

鉴于我有以下数据:

enter image description here

我想计算过去8个小时内销售的不同产品的数量,假设现在的时间是26/10/2018 23:35:00。

预期结果如下:

enter image description here

我正在qlikview工作。我不知道如何做表达来得到我想要的东西,尤其是当它涉及日期时间时。我应该使用agreegate还是计数?

提前感谢您的回答!

2 个答案:

答案 0 :(得分:0)

Kindly try this for required output 
    DECLARE @CURR_DATE DATETIME
SET @CURR_DATE=DATEADD(hour,0,'10/26/2018 23:30')

SELECT Product, count(category)
  FROM  Table_1 
where 
  AddedDate between  DATEADD(hour,-1,@CURR_DATE) and @CURR_DATE  
  GROUP BY Product,category,(DATEPART(hh, AddedDate))

答案 1 :(得分:0)

我建议为脚本中的每个记录定义一个标志,以避免棘手而复杂的集合分析,而这些分析很容易中断。

假设您将Datetime加载到某处,我会添加:

LOAD
...
Datetime,
If(Datetime > Today() - 8 / 24, 'Y', 'N') as SoldInLast8Hours
....

有了这个新维度,您将可以使用简单的集合分析,例如:

Sum({<SoldInLast8Hours = {'Y'}>} 1)

Count({<SoldInLast8Hours = {'Y'}>} DISTINCT EntryId)

如果每个交易行都有唯一的ID。