简体   繁体   English

使用 UPDATE、SUM 和 EXTRACT 函数从计算字段更新列

[英]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.

相关问题 Quicksight 计算字段:平均值之和? - Quicksight Calculated field: sum of average? SQL 添加新列作为任意计算字段 (Postgres / redshift) - SQL adding new column as arbitrary calculated field (Postgres / redshift) 从具有 T 和 Z 的列中提取时间戳 - Extract timestamp from column with T and Z 如何从字段名称具有特殊字符的 JSON 类型列中提取数据? - How to extract data from a JSON tye column which field name has special characters? 使用计算字段订购 QuerySnapShot - Ordering QuerySnapShot with calculated field 如何从 AWS Athena 中的 JSON 对象数组中提取字段? - How to extract a field from an array of JSON objects in AWS Athena? 如何使用用户可以在 getFields 的计算字段中更新的参数(Data Studio 社区连接器) - How to use a parameter which a user can update in a calculated field in getFields (Data Studio Community Connector) 为什么 dynamodb.update() 没有更新我表中的字段? - Why is dynamodb.update() is not updating the field in my Table? 如何使用(与物化视图兼容)SQL 从具有多个键值列表的 JSON 中提取值作为列? - How to extract a value as a column from JSON with multiple key-value lists using (a materialized view compatible) SQL? 如何在 Google Data Studio 中创建计算字段过滤器? - How to create Calculated Field Filters in Google Data Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM