CASE WHEN THEN END多條件判斷

2021-10-22 13:58:05 字數 2149 閱讀 4437

create table `employees` (

`emp_no` int(11) not null,

`birth_date` date not null,

`first_name` varchar(14) not null,

`last_name` varchar(16) not null,

`gender` char(1) not null,

`hire_date` date not null,

primary key (`emp_no`));

create table `dept_emp` (

`emp_no` int(11) not null,

`dept_no` char(4) not null,

`from_date` date not null,

`to_date` date not null,

primary key (`emp_no`,`dept_no`));

create table emp_bonus(

emp_no int not null,

received datetime not null,

btype smallint not null);

create table `salaries` (

`emp_no` int(11) not null,

`salary` int(11) not null,

`from_date` date not null,

`to_date` date not null, primary key (`emp_no`,`from_date`));

給出emp_no、

first_name、

last_name、

獎金型別btype、

對應的當前薪水情況salary以及獎金金額bonus。

bonus型別btype為1其獎金為薪水salary的10%,btype為2其獎金為薪水的20%,其他型別均為薪水的30%。 

當前薪水表示to_date='9999-01-01'

方式一:

case

when 條件1 then 結果1

when 條件2 then 結果2

when 條件3 then 結果3

.........

when 條件n then 結果n

end方式二:

case

when *** ='1' then '男'

when *** ='0' then '女'

else '其他' end

--注意:

這兩種方式,可以實現相同的功能。--

--第一種case when then 寫法 --

select e.emp_no,e.first_name,e.last_name,eb.btype,s.salary ,

(case when eb.btype = '1' then s.salary*0.1

when eb.btype = '2' then s.salary*0.2

else s.salary*0.3

end) as bonus

from employees e

join emp_bonus eb on e.emp_no = eb.emp_no

join salaries s on s.emp_no = e.emp_no

where s.to_date = '9999-01-01'

-- 第二種case when 寫法 --

select e.emp_no,e.first_name,e.last_name,eb.btype,s.salary ,

case eb.btype when '1' then s.salary*0.1

when '2' then s.salary*0.2

else s.salary*0.3

endas bonus

from employees e

join emp_bonus eb on e.emp_no = eb.emp_no

join salaries s on s.emp_no = e.emp_no

where s.to_date = '9999-01-01'

Nginx中if語句的判斷條件與多條件判斷詳解

一 if語句中的判斷條件 nginx 介紹 1 正規表示式匹配 等值比較 與指定正規表示式模式匹配時返回 真 判斷匹配與否時區分字元大小寫 與指定正規表示式模式匹配時返回 真 判斷匹配與否時不區分字元大vfjwwxi小寫 與指定正規表示式模式不匹配時返回 真 判斷匹配與否時區分字元大小寫 與指定正規...

多條件查詢

思路 1.獲取引數值 2.生成查詢條件 3.獲取查詢結果 4.繫結查詢選項 呼叫geturlhtml方法生成查詢url 例如 var y2013 pnvshihufu qbeijing sxuhuiqu 得到url變數值 protected string geturlval string name ...

多條件查詢

多條件查詢時在做專案的時候不可缺少的功能,雖然很簡單,但是自己還是記一下,對自己有用 查詢事件 private void button查詢 click object sender,eventargs e initial catalog uid pwd this.dataserver,this.dat...