Home > Software design >  SQL How to use IF query to create a new column from others
SQL How to use IF query to create a new column from others

Time:10-15

I have tables where I have a result of 0-1 0 is gone and 1 is. I need to write a query, and I totally don't know how to. If New_Def = 0 a Default = 1 then 'NEW' If New_Def = 1 a Default = 1 then = OLD.

CodePudding user response:

I think you are looking for case :

select * , case when New_Def = 0 and Default = 1 then 'NEW' 
                when New_Def = 1 and Default = 1 then 'OLD'
           else 'Unknown'
           end as Newcolumn
from table
  •  Tags:  
  • sql
  • Related