decode與case when的區別

2021-09-01 14:05:01 字數 610 閱讀 2094

求和:sum(decode(sign(xingji - 6),'',h.real_count,1,h.real_count,0))

decode相較於case when,函式裡面不能使用and連線多個條件,只能使用函式巢狀

例如:sum(decode(sign(xingji - 6),-1,decode(hh.quxian,18,h.real_count,19,h.real_count,20,h.real_count,24,h.real_count,34,h.real_count,35,h.real_count,0),0))

求和:sum(case when start_time = '24' then quantity else 0 end)

case when顯得有些臃腫,但是在多個條件連線時比較方便,例如:sum(case when start_time = '24' and city_code = '010' then quantity else 0 end)

另說明:sum()函式用於求和,sign()函式用於返回引數是大於0,還是小於0或者等於0,乙個例外是返回空:'';

例如:sign(1)--->1,sign(-1)--->-1,sign(0)--->0,sign(null)--->'';

ORACLE CASE 與 DECODE的用法

1.case的用法 select logid,userid,logtime,url,description,case when operatetype 0 then 新增 when operatetype 1 then 修改 else 刪除 end from log 2.decode的用法 sele...

Python中decode與encode的區別

1 字串在python內部的表示是unicode編碼,因此,在做編碼轉換時,通常需要以unicode作為中間編碼,即先將其他編碼的字元解碼 decode 成unicode,再從unicode編碼 encode 成另一種編碼。decode的作用是將其他編碼的字元轉換成unicode編碼,如str1,d...

decode的介紹與使用

decode的幾種用法 1 使用decode判斷字串是否一樣 decode value,if1,then1,if2,then2,if3,then3,else 含義為if 條件 值1 then return value 1 elsif 條件 值2 then return value 2 elsif 條...