相当于Impala EOMONTH

时间:2019-02-20 15:39:09

标签: sql impala

我的问题是,Impala中似乎不存在EOMONTH,所以我希望可以替代EOMONTH。我只想只返回与月末日期相对应的值。下面是我尝试过的查询,最后一行是我遇到的问题。

SELECT a.ticker,a.FieldName,a.DataSource,b.tickervalue, 
to_timestamp(CAST(tickervaluedate/1000 as bigint)) as tickervaluedate
FROM agronomycn.raw_crttickername AS a 
INNER JOIN agronomycn.raw_crttickervalue as b on a.TickerID = b.TickerID
WHERE a.ticker = 'C_FRONT2' AND a.fieldname = 'CLOSE' AND a.datasource = 'EXCH'
AND to_timestamp(CAST(b.tickervaluedate/1000 as BIGINT)) BETWEEN '2010-01- 01' AND '2019-01-01' 
AND to_timestamp(CAST(b.tickervaluedate/1000 as BIGINT)) = EOMONTH(to_timestamp(CAST(b.tickervaluedate/1000 as BIGINT)))

1 个答案:

答案 0 :(得分:2)

这可以结合使用truncadd_monthsdate_add来完成。

select date_add(add_months(trunc(dtCol,'MM'),1),-1)

这假定日期的字符串格式为yyyy-MM-ddyyyy-MM-dd HH:mm:ss