如何在Presto SQL中将unix时间戳转换为日期并从中提取月份

阿黛尔

我有以下查询:

    select cast(ov.ingestion_timestamp as date), date(ov.date_id), cast(ov.main_category as varchar), 
    sum(cast(ov.order_target as int)),
    sum(cast(ov.gmv_target as int))
    from tableA ov 
    inner join tableB cb
    on date(ov.date_id) = date(cb.ingestion_timestamp)
    inner join tableC loc  
    on date(ov.date_id) = date(loc.ingestion_timestamp)
    where MONTH(date(ov.ingestion_timestamp)) = month(current_date)
group by 1,2,3

在此处输入图片说明

我想获取ingestion_timestamp列的月份等于当前月份的记录。所有列值都存储为对象,因此我需要转换为它们各自的数据类型。我可以知道如何获取ingestion_timestamp列的月份吗?

谢谢。

专线小巴

我建议不要cast在该where子句中使用:这效率低下,因为该函数需要在过滤之前应用于每行。

相反,您可以计算与该月初相对应的时间戳,并将其用于直接过滤:

where ingestion_timestamp >= to_unixtime(date_trunc(month, current_date))

如果您有将来的日期,则可以添加上限

where 
    ingestion_timestamp >= to_unixtime(date_trunc(month, current_date))
    and ingestion_timestam < to_unixtime(date_trunc(month, current_date) + interval '1' month)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Presto中将时间戳转换为日期?

如何在CockroachDB中将Unix时间戳转换为日期?

如何在Excel中将Unix纪元时间戳转换为人类可读的日期/时间?

如何在 presto sql 中获取日期

如何在铸造轮廓中将Unix时间戳转换为日期?

如何在PHP mongo查询中将unix时间戳转换为mongodb日期

如何在PostgreSQL中将unix时间戳列转换为日期格式?

如何在graphlab(Python 2.7)中将日期从Unix时间戳转换为人类可读的格式

如何在 D3 中将 unix 时间戳转换为日期对象?

如何在MySQL中将时间戳转换为日期时间?

如何仅使用Busybox工具将具有指定月份的日期转换为Unix时间戳?

如何在CMake中将UNIX时间戳转换为ISO

如何在presto中将列转换为数组

如何在 Firebird 中将 Unix 时间转换为日期时间?

如何在Java中将时间戳转换为日期格式

如何在DataFrame中将时间戳转换为日期格式?

如何在Bash中将时间戳转换为日期?

如何在C#中将时间戳转换为日期?

如何在标准SQL中将纪元时间戳转换为日期

如何在SQL查询中将日期转换为时间戳?

如何在Golang中将GMT日期转换为UNIX时间?

如何使用标准 SQL 在 Google Bigquery 中将日期时间转换为日期,或者如何从日期时间的 where 语句中提取年份?

如何仅在mysql中将此日期转换为unix时间戳?

如何使用 mongoDB 在 Spring boot2 中将日期转换为纪元(unix 时间戳)?

如何在kotlin中将纪元时间戳转换为unix十六进制时间戳?

如何在Presto / Hive中将日期格式YYYY-MM-DD转换为整数YYYYMMDD?

如何将Unix时间戳转换为日期时间

如何在SQL中将varchar日期转换为日期时间

如何在presto sql中将行的不同值变成列