2012-04-17 50 views

回答

3

如果你只想要一個yes如果是1,並在no所有其他價值的結果,你可以這樣做:

select case 
     when MyColumn = 'yes' then 1 
     else 0 
    end as MyDerivedValue 
from MyTable 

或者,你可以更具體:

select case MyColumn 
     when 'yes' then 1 
     when 'no' then 0 
     when 'maybe' then 2 
     else -1 
    end as MyDerivedValue 
from MyTable 
+0

什麼是MyDerivedValue? – antonpug 2012-04-17 16:56:28

+0

@antonpug - 它是該列的別名 – Lamak 2012-04-17 17:01:48