2017-10-10 36 views
0

我期待能够创建一个表,其中包含所有日期(含)之间的最小和最大日期从另一个表。见简单的查询下面让这些日期在Hive SQL中生成日期

-- Get the min and max dates from the table 
select min(date(sale_date)) as min_date, 
     max(date(sale_date)) as max_date 
from TABLE; 

我花了最后一个小时google搜索这个问题,并已发现在对MySQL和Oracle SQL但不是在蜂巢SQL这样的尝试,我一直无法转换为Hive SQL。如果任何人有任何想法如何做到这一点,请让我知道。提前感谢你。

回答

0

好吧,这不是我的答案。一位同事能够回答。尽管如此,我认为重要的是我会展示我的同事为您未来的收益提供的解决方案。它假定您创建了包含最短日期和最长日期的表格。

CREATE TABLE TABLE_2 
STORED AS AVRO 
LOCATION 'xxxxxx' 
AS 
SELECT date_add (t.min_date,pe.i) AS date_key 
FROM TABLE_1 t 
LATERAL VIEW 
posexplode(split(space(datediff(t.max_date,t.min_date)),' ')) pe AS i,x;