Home > database >  How to use any_value in bigquery
How to use any_value in bigquery

Time:01-04

I am looking to derive the columns 2 and 3 from 1 and 4 using sql, need advise

enter image description here

output logics for col_2 and col_3

  1. any of the values in col_1 group by col_4 is True , then col_2 is true col_3 is false
  2. all the values in col_1 group by col_4 is false, then col_2 is false and col_3 is true
  3. all the values in col_1 group by col_4 is true , then col_2 is false and col_3 is false

CodePudding user response:

You seems to want enter image description here

CodePudding user response:

One way would be to count true and false values for each col_4 key inside a CTE or a subquery (whichever way works for you). Then perform a join with the original table. That way, you can then derive col_2 and col_3 directly by checking the counts of True and False in the final select statement.

  • Related