【问题标题】:How to count how many days since the user was active on the platform in SQL?如何计算用户在 SQL 平台上活跃的天数?
【发布时间】:2021-10-26 16:35:34
【问题描述】:

我想知道距离此人第一次旅行过去了多少天。

我正在尝试这个:

DATEDIFF(day, first_completed_trip_timestamp, CURRENT_DATE) AS days_since_ft

我得到这个错误:

QueryValidation: user_error: Attempt 1: presto: query failed (200 OK): "USER_ERROR: com.facebook.presto.sql.analyzer.SemanticException: line 11:16: Column 'day' cannot be resolved"

【问题讨论】:

    标签: sql presto


    【解决方案1】:

    您可以通过减去值将其作为间隔返回:

    (CURRENT_DATE - first_completed_trip_timestamp) as days_since_ft
    

    如果您特别想要天数,请在间隔上使用day()

    day(CURRENT_DATE - first_completed_trip_timestamp) as days_since_ft
    

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2020-10-02
      • 2020-07-06
      • 1970-01-01
      • 2012-05-24
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-06
      相关资源
      最近更新 更多