合肥網(wǎng)站建設(shè)優(yōu)化網(wǎng)絡(luò)營銷是什么工作主要干啥
目錄
題目
準(zhǔn)備數(shù)據(jù)
分析數(shù)據(jù)
總結(jié)
題目
編寫解決方案,計算每個雇員的獎金。如果一個雇員的 id 是?奇數(shù)?并且他的名字不是以?'M'
?開頭,那么他的獎金是他工資的?100%
?,否則獎金為?0
?。
返回的結(jié)果按照?employee_id
?排序。
準(zhǔn)備數(shù)據(jù)
Create table If Not Exists Employees (employee_id int, name varchar(30), salary int);
Truncate table Employees;
insert into Employees (employee_id, name, salary) values ('2', 'Meir', '3000');
insert into Employees (employee_id, name, salary) values ('3', 'Michael', '3800');
insert into Employees (employee_id, name, salary) values ('7', 'Addilyn', '7400');
insert into Employees (employee_id, name, salary) values ('8', 'Juan', '6100');
insert into Employees (employee_id, name, salary) values ('9', 'Kannon', '7700');
分析數(shù)據(jù)
selectemployee_id,if((employee_id % 2 = 1 and name not like 'M%'),salary,0) bonus
from employees
order by employee_id;
總結(jié)
判斷奇數(shù):num % 2 =1
模糊匹配:使用關(guān)鍵字like
%:匹配多個字符,
?:匹配一個字符