【问题标题】:How to get latest 3 months records in presto sql如何在 presto sql 中获取最近 3 个月的记录
【发布时间】:2020-03-14 13:57:34
【问题描述】:

我想查找用户 A 在过去 3 个月内的登录频率,但不知何故,我在 WHERE 子句中的日期过滤器有一些错误.. 不确定以下是否是检索最近 3 个月记录的正确方法presto sql。

select userid, count(*)
from user_login
where userid = 3321 and date(from_unixtime(cast(date_login as int)) >= date_add('day',-90,current_date))
group by 1 

【问题讨论】:

  • date_login的数据类型是什么?
  • 你的日期函数又少了一个)。

标签: sql presto


【解决方案1】:

这不行吗?

where date_login > cast(date_add(day, -90, current_date) as timestamp)

或:

where date_login > cast(current_date - interval '90' day as timestamp)

【讨论】:

  • @adelle 。 . .您应该能够将该值转换为时间戳。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-30
  • 1970-01-01
  • 2020-09-12
  • 2015-07-07
  • 2011-03-08
相关资源
最近更新 更多