Hive SQL:如何查找和标记日期范围内的事件
Hive SQL: How to find and flag occurrence within date range
我下面有一组数据,我需要根据下面的 phone 号码和呼叫日期查找并标记谁在 5 天内回电。我如何在配置单元中执行此操作?谢谢您的帮助。
PhoneNumber CallDate Callback_Flag
5713555841 5/6/2016 Yes
5713555841 5/9/2016 No
5713555841 5/19/2016 No
5714390412 1/15/2016 Yes
5714390412 1/19/2016 No
5714390412 2/16/2016 No
5714390412 3/24/2016 No
5756379433 3/11/2016 Yes
5756379433 3/16/2016 No
5756379433 4/12/2016 No
使用lead()
:
select t.*,
(case when lead(calldate) over (partition by phonenumber order by calldate) > date_add(CallDate, 5)
then 'Yes'
else 'No'
end)
from t;
我下面有一组数据,我需要根据下面的 phone 号码和呼叫日期查找并标记谁在 5 天内回电。我如何在配置单元中执行此操作?谢谢您的帮助。
PhoneNumber CallDate Callback_Flag
5713555841 5/6/2016 Yes
5713555841 5/9/2016 No
5713555841 5/19/2016 No
5714390412 1/15/2016 Yes
5714390412 1/19/2016 No
5714390412 2/16/2016 No
5714390412 3/24/2016 No
5756379433 3/11/2016 Yes
5756379433 3/16/2016 No
5756379433 4/12/2016 No
使用lead()
:
select t.*,
(case when lead(calldate) over (partition by phonenumber order by calldate) > date_add(CallDate, 5)
then 'Yes'
else 'No'
end)
from t;