[英]Updating a column from a calculated field using UPDATE, SUM & EXTRACT functions
I want to update the 'duration_s' column (numeric), so I can obtain the duration in minutes & hours and also obtain velocity, using the given distance traveled.我想更新“duration_s”列(数字),所以我可以使用给定的行驶距离获得以分钟和小时为单位的持续时间,还可以获得速度。
but first I need to transform ride_length (schema - time) into an integer但首先我需要将ride_length(模式 - 时间)转换为 integer
so I tried, but I am stuck.所以我尝试了,但我被卡住了。 this is the query I tried to write:这是我试图写的查询:
WITH calc AS (
SELECT
SUM((EXTRACT(HOUR FROM ride_length)*3600)+(EXTRACT(MINUTE FROM ride_length)*60)+EXTRACT(SECOND FROM ride_length)) AS seconds
FROM `fresh-ocean-357202.Cyclistic.Cyclistic_yearly`
)
UPDATE `fresh-ocean-357202.Cyclistic.Cyclistic_yearly`
SET duration_s = calc.seconds
WHERE TRUE
these field names have NULL are set as NUMERIC as its data type这些字段名称具有 NULL 设置为 NUMERIC 作为其数据类型
I already got it.我已经明白了。 Instead of doing this:而不是这样做:
UPDATE `fresh-ocean-357202.Cyclistic.Cyclistic_yearly`
SET duration_s = SUM((EXTRACT(HOUR FROM ride_length)*3600)+(EXTRACT(MINUTE FROM ride_length)*60)+EXTRACT(SECOND FROM ride_length))
WHERE TRUE
I did this:我这样做了:
UPDATE `fresh-ocean-357202.Cyclistic.Cyclistic_yearly`
SET duration_s = (EXTRACT(HOUR FROM ride_length)*3600)+(EXTRACT(MINUTE FROM ride_length)*60)+EXTRACT(SECOND FROM ride_length)
WHERE TRUE
I just removed the SUM function into the SET function我刚刚将 SUM function 删除到 SET function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.