1. 程式人生 > >sql-case,when的多條件組合寫法

sql-case,when的多條件組合寫法

1.decode 寫法簡介,只能寫表示式。

例:decode(表示式,條件1,值1,條件2,值2··· 預設值) 

無法滿足多條件的寫法,比如,我要a-b = 0 且a !=0 用decode沒法實現

2.case when 能寫多條件

寫法一:case 表示式 when 條件1 then 值1

                                   when 條件2 then 值2

                                  ····

                                  else 值  end

寫法二:case when a-b=0 and a != 0 then 值

                        when  ··· then ···

                        else  值  end