1
我有attendancedata有日期,EMPNO timein /超時列沒有周末日期的表格(星期五和星期六是週末)在Vertica的計數不包括Vertica的週末
請注意: 1,表是DateTimeAttendance 2,對於缺席的員工,Time-In爲NULL。
所以我的條件在這裏是
TimeIn = NULL
我嘗試了數據Vertica的以下分析功能,並得到了outpout如下
select name, date, CONDITIONAL_TRUE_EVENT(date - lag(date)>1) over (partition by name order by date) as ConsecutiveDatesCounter
from DateTimeAttendance
where timein is null group by name,date ;
樣本輸出中:
name date ConsecutiveDatesCounter
Aaron Gadsen 19/3/2014 0
Aaron Gadsen 23/3/2014 1
Aaron Gadsen 24/3/2014 1
Aaron Gadsen 25/3/2014 1
Aaron Gadsen 26/3/2014 1
Aaron Gadsen 27/3/2014 1
Aaron Gadsen 30/3/2014 2
Aaron Gadsen 31/3/2014 2
這裏28/3/2014和29/3/2014是週末,所以我想ConsecutiveDatesCounter 1不應該改變爲2,它應該繼續作爲1
我想要得到的輸出如下
name date ConsecutiveDatesCounter
Aaron Gadsen 19/3/2014 0
Aaron Gadsen 23/3/2014 1
Aaron Gadsen 24/3/2014 1
Aaron Gadsen 25/3/2014 1
Aaron Gadsen 26/3/2014 1
Aaron Gadsen 27/3/2014 1
Aaron Gadsen 30/3/2014 1
Aaron Gadsen 31/3/2014 1
上述結果接着查詢將如下
select name, count(1) num_days, min(date) startdate, max(date) enddate
from (select name, date, CONDITIONAL_TRUE_EVENT(date - lag(date)>1) over (partition by name order by date) as ConsecutiveDatesCounter
from DateTimeAttendance where timein is null group by name,date) as consecutive
group by name, consecutiveDatesCounter order by startdate;
最終輸出應是像這樣:
name num_days startdate enddate
Aaron Gadsen 1 19/3/2014 19/3/2014
Aaron Gadsen 7 23/3/2014 31/3/2014
請幫我解決週末的這個問題,在這種情況下..
由於提前