Skip to content
Advertisement

Logic for backward updation based on parent value

I have below tables with data as below

Table_Cell

Table_column

Table_row

I need to update SwitchCol in Table_column and Switchrow in Table_row

Logic is

If for an column_id in Table_column, all the combination with row_id in Table_row,present in table Table_Cell is 1, then make the SwitchCol =1 for that column_id Similary, for an id in Table_row, all the combination of Table_row with id in Table_column in table Table_Cell is 1, then make Switchrow=1 for that row_id

Eg: For column_id =55 , its combination with Table_row table in table Table_Cell (5522,5533,5544) has SwitchCell =1, so SwitchCol for 55 will be 1, But SwitchCol for 11 will be 0 (as (1122,1133,1144) has 1,0,1 which is off in one case.

Please help me in the logic. Looking for sql query

Advertisement

Answer

I think you just want min() and a correlated subquery:

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