![](/img/trans.png)
[英]Extract date,month,year and month name from the unix timestamp with postgresql
[英]How to cast unix timestamp as date and extract month from it in Presto SQL
我有以下查询:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.