Extract Calenderweek, year AND update the table with new values

Viewed 22

I am totally new to SQL & Bigquery even though I am trying to learn I habe an obvious lack of knowledge.

I have a table with a date as timestamp and try to extract calenderweek and year. I know how select it the right way but the results end up in a temp table.

My wish is to update the same table with the same query and add the two columns with the specific values.

I tried to use informations from here but I get stuck in the syntax: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#update_statement

I am open to any advices.

timestamp = Name of my column with the date

SELECT timestamp, EXTRACT (ISOWEEK FROM timestamp) AS KW, EXTRACT (YEAR FROM timestamp) AS Jahr,

FROM MyTable AS date;

1 Answers

Finally found the solution: UPDATE MyTable SET KW = EXTRACT (ISOWEEK FROM timestamp), Year_2 = EXTRACT (YEAR FROM timestamp)

WHERE Year is null;

Related