2017-02-13 170 views
2

我创建的具有时间戳列(数据类型是时间戳)以下列格式蜂房表:蜂巢时间戳查询

2017年1月23日21:23:17.261456

然而,当我选择像所以。它不能正常工作。它会在时间戳后选择日期。该列应该是一个字符串还是我使用查询错误?

select * from example where time_created < '2017-01-01 22:30:57.375117' 
+0

时间戳文字不能很好地与毫秒工作,更有甚者用微秒......实验用''2017年1月1日22:30:57''和'投( '2017-01-01 22:30:57'as TimeStamp)'''cast('2017-01-01 22:30:57.375'as TimeStamp)'等等等来放大这个问题。 –

回答

0

您需要更改过滤器的数据类型,例如时间戳,以字符串比较可能是问题。尝试使用from_utc_timestamp('2017-01-01 22:30:57.375117')或from_unix()命令。

-1
select from_unixtime(unix_timestamp('2015-12-23 22:30:57.375' ,'yyyy-MM-dd HH:mm:ss.SSS')) ; 
2

我有同样的问题:字符串和时间戳之间的比较没有自动完成。 此制定了我:

select * from example 
     where unix_timestamp(time_created, 'yyyy-MM-dd HH:mm:ss.SSS') < 
       unix_timestamp('2017-01-01 22:30:57.375117','yyyy-MM-dd HH:mm:ss.SSS')