Home > Blockchain >  Calculated column based on another calculated field BigQuery
Calculated column based on another calculated field BigQuery

Time:05-25

Hello I'm trying to use an already calculated value in a select to calculate another value, for example:

SELECT 1 1 AS two, two 2 AS four FROM table

is this possible in BigQuery? I'm sure it's on SAS with the keyword CALCULATED as follows:

SELECT 1 1 as two, CALCULATED two 2 AS four FROM table

Thank you,

CodePudding user response:

Below is example of how I personally approach such scenario (quite frequently btw)

SELECT two, two   2 AS four 
FROM table, UNNEST([STRUCT(1 1 as two)])     

CodePudding user response:

You cannot use an alias in same select. An option could be use a subselect:

WITH my_table AS (
  SELECT 1 1 AS two FROM table
)
SELECT two   2 AS four FROM my_table
  • Related