admin管理员组文章数量:1026989
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?
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?
本文标签: sqlHow can I convert an INTERVAL datatype to DATETIME or TIMESTAMPStack Overflow
版权声明:本文标题:sql - How can I convert an INTERVAL datatype to DATETIME or TIMESTAMP - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745649820a2161248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论