最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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?

Post a comment

comment list (0)

  1. No comments so far