最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - How can I convert an INTERVAL datatype to DATETIME or TIMESTAMP - Stack Overflow

programmeradmin2浏览0评论

I'm trying to calculate the subtraction of two columns(started_at & ended_at) with datatypes of TIMESTAMP but the result comes out as INTERVAL datatype. How can I convert the result datatype from INTERVAL to TIMESTAMP or TIME etc.

SELECT 
  member_casual,
 AVG(trip_duration) AS avg_trip_duration,
 EXTRACT(DAYOFWEEK FROM trip_duration) AS dayofweek


FROM(
  SELECT
  member_casual,
  ended_at - started_at AS trip_duration
  FROM `helical-fin-439209-b4.cyclistic.202201_tripdata`)


GROUP BY member_casual,trip_duration
ORDER BY avg_trip_duration DESC;

Because trip_duration is INTERVAL datatype I can't extract the DAYOFWEEK from it. How can I fix this?

发布评论

评论列表(0)

  1. 暂无评论