a表有三个字段,用户user_id ,出发日期stat_date,归来日期 back_data
b表是假期表(只存所有法定节假日信息)有两个字段,日期 day,假期类型type
获取用户在出发与归来日期之间是否是假期,并获取假期类型。
set hive.mapred.mode=nonstrict;
select
user_id
,start_date
,back_date
,festival
from
(
SELECT
user_id
,start_date
,back_date
,IF(b.day>=start_date and b.day<=back_date,type,null) as festival
FROM a,b
) t
group by
user_id
,start_date
,back_date
,festival
这样产生笛卡尔积,数据量增加很多倍,而且很浪费资源,请教各位老哥,有没有更有效的方式?先行谢过!
(想着用left join 但是因为a表的日期是区间,没法关联,就放弃了。)
用exists去找出发日期和归来日期中间有假期的就行,select * from a where exists (select 1 from b where b.day between a.start_date and a.back_date)