当前位置:网站首页>1873. 计算特殊奖金
1873. 计算特殊奖金
2022-08-05 02:32:00 【只是六号z】
1873. 计算特殊奖金
前言
表: Employees
+-------------+---------+
| 列名 | 类型 |
+-------------+---------+
| employee_id | int |
| name | varchar |
| salary | int |
+-------------+---------+
employee_id 是这个表的主键。
此表的每一行给出了雇员id ,名字和薪水。
写出一个SQL 查询语句,计算每个雇员的奖金。如果一个雇员的id是奇数并且他的名字不是以’M’开头,那么他的奖金是他工资的100%,否则奖金为0。
Return the result table ordered by employee_id.
返回的结果集请按照employee_id排序。
查询结果格式如下面的例子所示。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/calculate-special-bonus
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例1:
输入:
Employees 表:
+-------------+---------+--------+
| employee_id | name | salary |
+-------------+---------+--------+
| 2 | Meir | 3000 |
| 3 | Michael | 3800 |
| 7 | Addilyn | 7400 |
| 8 | Juan | 6100 |
| 9 | Kannon | 7700 |
+-------------+---------+--------+
输出:
+-------------+-------+
| employee_id | bonus |
+-------------+-------+
| 2 | 0 |
| 3 | 0 |
| 7 | 7400 |
| 8 | 0 |
| 9 | 7700 |
+-------------+-------+
解释:
因为雇员id是偶数,所以雇员id 是2和8的两个雇员得到的奖金是0。
雇员id为3的因为他的名字以'M'开头,所以,奖金是0。
其他的雇员得到了百分之百的奖金。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/calculate-special-bonus
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
1、union + not like
select
employee_id, salary as bonus
from Employees
where employee_id % 2 != 0 and name not like 'M%'
union
select
employee_id, salary*0 as bonus
from Employees
where employee_id % 2 = 0 or name like 'M%'
order by employee_id;
2、if
select
employee_id,if(employee_id % 2 = 0 or name like 'M%', 0 , salary) as bonus
from
Employees
order by
employee_id ;
3、if + left + mod
select employee_id,
if(mod(employee_id,2) != 0 and left(name,1) != 'M',salary,0) bonus
from Employees
order by employee_id;
边栏推荐
- Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit
- 如何看待自己的羞愧感
- C学生管理系统 指定位置插入学生节点
- 用@Mapper查询oracle的分区情况报错
- 常见的硬件延迟
- 如何模拟后台API调用场景,很细!
- Gantt chart is here, project management artifact, template is used directly
- Amazon Cloud Technology joins hands with Thundersoft to build an AIoT platform for industry customers
- 【 2 】 OpenCV image processing: basic knowledge of OpenCV
- Hypervisor related knowledge points
猜你喜欢
Compressed storage of special matrices
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
QT语言文件制作
[C language] Detailed explanation of stacks and queues (define, destroy, and data operations)
C语言实现简单猜数字游戏
leetcode 15
Pisanix v0.2.0 发布|新增动态读写分离支持
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
CPDA|运营人如何从负基础学会数据分析(SQL)
C language implements a simple number guessing game
随机推荐
继承关系下构造方法的访问特点
Pisanix v0.2.0 发布|新增动态读写分离支持
Error: Not a signal or slot declaration
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
【LeetCode刷题】-数之和专题(待补充更多题目)
select 标签自定义样式
采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向
树表的查找
shell statement to modify txt file or sh file
Matlab画图3
1484. 按日期分组销售产品
重新审视分布式系统:永远不会有完美的一致性方案……
the mechanism of ideology
The 20th day of the special assault version of the sword offer
LPQ(局部相位量化)学习笔记
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
C语言实现简单猜数字游戏
C学生管理系统 头添加学生节点
[机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)