如何在aws athena中查询unix epoch timestamp中的时间

How to query the time in unix epoch timestamp in aws athena

我有一个简单的 table 包含 节点、消息、开始时间、结束时间 详细信息,其中开始时间和结束时间在 unix 时间戳中。我运行的查询是:

select node, message, (select from_unixtime(starttime)), (select from_unixtime(endtime)) from table1 WHERE try(select from_unixtime(starttime)) > to_iso8601(current_timestamp - interval '24' hour) limit 100

查询不工作并抛出语法错误。

我正在尝试从 table 中获取以下信息:

您不需要“额外”选择,也不需要 to_iso8601 在 where 子句中:

WITH dataset AS (
    SELECT * FROM (VALUES   
       (1627409073, 1627409074),
       (1627225824, 1627225826)
 ) AS t (starttime, endtime))

SELECT from_unixtime(starttime), from_unixtime(endtime)
FROM
dataset
WHERE from_unixtime(starttime) > (current_timestamp - interval '24' hour) limit 100

输出:

_col0 _col1
2021-07-27 18:04:33.000 2021-07-27 18:04:34.000

要搜索上周您可以使用

WHERE your_date >= to_unixtime(CAST(now() - interval '7' day AS timestamp))