I have a table:
table1
unique_id col_id col_nm col_val sequ
1 1 testq 1 100 1
1 2 testc 1 abc 1
1 1 testq 1 101 2
1 2 testc 1 xyz 2
1 5 test 5 10 1
1 8 test 6 100 1
2 1 testq 1 100 1
2 2 testc 1 pqr 1
2 1 testq 1 101 2
2 2 testc 1 xxy 2
2 5 test 5 qqw 1
2 8 test 6 100 1
I need to insert new rows in the table based on the following condition:
- Find
unique_id
andsequ
ofcol_id
= 1 andcol_nm
= 'testq 1' andcol_val
= 100 - Find
col_val
ofcol_id
= 2 andcol_nm
= 'testc 1' andsequ
= {sequ
of step 1} and unique_id = {unique_id
of step 1}. - Insert a new row for the corresponding
unique_id
, with col_id = 100, col_nm = 'test q100c',col_val
= {col_val found in step 2},sequ
= {sequ found in step 2}
The output would be:
unique_id col_id col_nm col_val sequ
1 1 testq 1 100 1
1 2 testc 1 abc 1
1 1 testq 1 101 2
1 2 testc 1 xyz 2
1 5 test 5 10 1
1 8 test 6 100 1
1 100 test q100c abc 1
2 1 testq 1 100 2
2 2 testc 1 pqr 2
2 1 testq 1 101 2
2 2 testc 1 xxy 2
2 5 test 5 qqw 1
2 8 test 6 100 1
2 100 test q100c pqr 2
Is there anyway in SQL to achieve this?