Skip to content
Advertisement

column creation on condition – sql

Table:

Aim to create a col4 and copy value from col3 to col4 if (with partition by on col2):

Wherever “cat” is present in col3, then check if col1+5 exists, if yes then value of col3 from “cat” row goes to that col4(whose col1 value is cat’s “col1+5”)

output:

Advertisement

Answer

If I understand correctly, you can use left join:

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