MySQL高阶1873-计算特殊奖金

目录

题目

准备数据

分析数据

总结


题目

编写解决方案,计算每个雇员的奖金。如果一个雇员的 id 是 奇数 并且他的名字不是以 'M' 开头 ,那么他的奖金是他工资的 100% ,否则奖金为 0 。

返回的结果按照 employee_id 排序。

准备数据

sql 复制代码
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');

分析数据

sql 复制代码
select
    employee_id,
    if((employee_id % 2 = 1 and name not like 'M%'),salary,0) bonus
from employees
order by employee_id;

总结

判断奇数:num % 2 =1

模糊匹配:使用关键字like

%:匹配多个字符,

?:匹配一个字符

相关推荐
写后端的胖头鱼11 小时前
【高频面试题】FullText 全文索引(MySQL)
数据库·mysql·索引·全文索引
路远的数据库笔记11 小时前
SQL Server迁移国产数据库怎么做?九套口岸库零停机割接实战
数据库·经验分享·sqlserver·dba
樱花落木兰11 小时前
分布式登录实战:Session 会话共享改造,Redis 存储用户登录状态
java·javascript·数据库·redis·分布式·缓存
kaiyou202612 小时前
用户研究岗秋招,统计分析能力怎么学习和证明?
数据库·python·学习
mjhcsp12 小时前
DeepSeek V4.1 Flash 批量处理效能实测
java·前端·数据库
ShineWinsu12 小时前
对于Redis:Steam、Geospatial、Hyperloglog、Bitmap、Bitfield类型的解析
数据库·c++·redis·分布式·缓存·面试·zset
lie..12 小时前
30天从零开始学AI应用开发(Day 17):ChromaDB 上手:给本地文档建一个“外挂大脑”
数据库·人工智能·oracle
code_whiter13 小时前
01-MySQL数据库基础
数据库·mysql
weixin_3823952313 小时前
本地部署 ERP 选型记录:从 Excel 到轻量系统的这几年
数据库·人工智能·数据挖掘
2401_8914092614 小时前
期货量化用得上的几类行情数据:逐笔、Level2、分钟线和五档tick
数据库