I am looking to derive the columns 2 and 3 from 1 and 4 using sql, need advise
output logics for col_2
and col_3
- any of the values in col_1 group by col_4 is True , then col_2 is true col_3 is false
- all the values in col_1 group by col_4 is false, then col_2 is false and col_3 is true
- 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:
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.