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?