Google BigQuery Error: Unrecognized name
With BigQuery, you cannot use the derived column within the same select clause. Instead, you will need to build another select clause on top of existing select and use the derived column for further calculations. Look at the below example:
You have a query in Google BigQuery that looks like this:
\n\n SELECT client, begindate, enddate, \n LAG(enddate,1) OVER (PARTITION BY client ORDER BY begindate, \n client) AS lag,\n ROUND(DATE_DIFF(DATE(begindate), lag, DAY)) as diff\n FROM\n db LIMIT 100;\n
\n\nBut it's throwing the error "Error: Unrecognized name: lag at ....."
\n\nSolution:
With BigQuery, you cannot use the derived column within the same select. You need to build another select on top of existing select where the derived field is present. Like given below,
\n\nSELECT client,begindate, enddate,lag,\nROUND(DATE_DIFF(DATE(begindate), lag, DAY)) as diff\nFROM (\n SELECT client, begindate, enddate, \n LAG(enddate,1) OVER (PARTITION BY client ORDER BY begindate, \n client) AS lag, \n FROM\n db LIMIT 100;\n ) AS t\n
Ryan-Dallas
posted onEnjoy great content like this and a lot more !
Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds
Post Comment