我的问题是,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)))
答案 0 :(得分:2)
这可以结合使用trunc
,add_months
和date_add
来完成。
select date_add(add_months(trunc(dtCol,'MM'),1),-1)
这假定日期的字符串格式为yyyy-MM-dd
或yyyy-MM-dd HH:mm:ss
。