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

I'm trying to calculate the subtraction of two columns(started_at & ended_at) with datatypes o

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745649822a4638194.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信