Home > Net >  Add calculated values into column
Add calculated values into column

Time:09-28

enter image description here

Im trying to insert ended_at - started_at as duration into the duration_seconds column

CodePudding user response:

You need to run an SQL UPDATE statement to update value of duration_seconds
Something like this:

UPDATE all_trip
SET duration_seconds = DATETIME_DIFF(started_at, ended_at, SECOND)
-- safe check to only updating the record that is not calculated
WHERE duration_seconds IS NULL;

I use DATETIME_DIFF function, assuming that you're using Google Big Query (observed from your captured screenshot).

CodePudding user response:

Use this query:

SELECT t.started_at , t.ended_at , t.ended_at - t.started_at AS duration_seconds 
FROM   tableName as t
  •  Tags:  
  • sql
  • Related