【发布时间】:2017-10-22 17:22:37
【问题描述】:
我在 Hive 中有一张表如下:
|attribute | start_date | end_date |
|----------+------------+------------+
| x | 10-01-2014 | 03-31-2015 |
| x | 04-01-2015 | 09-30-2015 |
| x | 10-01-2015 | 03-31-2016 |
| x | 04-01-2016 | 09-30-2016 |
| y | 10-01-2015 | 03-31-2016 |
| y | 04-01-2016 | 09-30-2015 |
我想获得一个仅包含在 10-01-2014 和 09-30-2016 之间发生的所有属性的不同列表,但它们必须在 (10-01-2014, 04-01- 2015 年、2015 年 10 月 1 日、2016 年 4 月 1 日)。
我试过了:
select distinct(attribute),min(start_date) ,max(end_date)
from table
where
max(end_date) >='03-31-2016'
and min(effective_start_date) <='2015-01-01'
但这并不能阻止任何差距。任何帮助将不胜感激。
【问题讨论】:
-
请发布具有预期输出的表格。为什么您的查询中有
min()和max()函数? “每个人都必须有一个开始日期”是什么意思?您是指一系列重叠的(start_date, end_date)行吗?请澄清您的问题。
标签: sql date filter hive range