SQL CASE的使用例子

2021-09-18 01:24:09 字數 1155 閱讀 3018

在sql的case語句相當於常用的程式設計邏輯if ,else,只要前面的條件滿足,就不會再去執行下面的語句

例子:select principal_ids,principal_names from materials_data  

where material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like 

case

when (select count(1) from  materials_data where material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like '%e06%' ) >= 1 then  '%e06%' 

when (select count(1) from  materials_data where material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like '%e06%' ) < 1 then ''

end 

也可以寫成如下:

select principal_ids,principal_names from materials_data  

where  material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like 

case

when (select count(1) from  materials_data where material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like'%e06%' ) > 1 then  '%e06%' 

when (select count(1) from  materials_data where material_category like '%z003%' and department_name = '新產品開發中心'

and part_no like '%e06%' ) < 1 then ''

else '%e06%'  end 

jQuery cookie的使用例子

這是乙個jquery cookie的使用例子,通過本示例的學習希望朋友們能熟悉在引入jquery.cookie.js外掛程式後,如何去使用它,你可以了解到cookie天數設定 日期設定 多個cookie的設定 如何獲取cookie 通過 date 物件設定過期日期為 3 天後的那天 設定有效期天數等...

使用引數的例子

usr bin python filename cat.py import sys def readfile filename print a file to the standard output.f file filename while true line f.readline if len ...

Mutex Object的使用例子

include include define threadcount 2 handle ghmutex dword winapi writetodatabase lpvoid int main void create worker threads for i 0 i threadcount i wa...