Skip to content
Advertisement

GBQ SQL: For each unique value in Column A, if value ‘X’ appears in Column B….then create new Column C with value ‘Y’, else ‘N’

I’m using Google Big Query Standard SQL. Trying to figure out how to write this code. I have this table.

For each unique value in Column A, if the Column B has a value of ’10’, then create a new Column C with value ‘Y’, else ‘N’.

Results should look like this.

In this result, since ‘1’ has at least once instance of ’10’, all rows ‘1’ will be assigned a ‘Y’ value in new column C.

Advertisement

Answer

Just use case and window functions:

BigQuery has full support for booleans, so why use 'Y' and 'N', when you can use:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement