当前位置:网站首页>1873. The special bonus calculation
1873. The special bonus calculation
2022-08-05 02:32:00 【just six 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;
边栏推荐
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
- [LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
- Error: Not a signal or slot declaration
- the mechanism of ideology
- Short domain name bypass and xss related knowledge
- How to deal with your own shame
- mysql tree structure query problem
- 关于#sql shell#的问题,如何解决?
- 力扣-二叉树的前序遍历、中序遍历、后序遍历
- 转:查尔斯·汉迪:你是谁,比你做什么更重要
猜你喜欢
shell statement to modify txt file or sh file
[ROS] (10) ROS Communication - Service Communication
蚁剑高级模块开发
VSCode Change Default Terminal how to modify the Default Terminal VSCode
基于左序遍历的数据存储实践
线上MySQL的自增id用尽怎么办?
C语言实现简单猜数字游戏
".NET IoT from scratch" series
iNFTnews | What can NFTs bring to the sports industry and fans?
Flink 1.15.1 集群搭建(StandaloneSession)
随机推荐
行业案例|世界 500 强险企如何建设指标驱动的经营分析系统
Error: Not a signal or slot declaration
Go 微服务开发框架 DMicro 的设计思路
如何看待自己的羞愧感
线上MySQL的自增id用尽怎么办?
02 [Development Server Resource Module]
View handler 踩坑记录
SDC简介
the mechanism of ideology
【日常训练】1403. 非递增顺序的最小子序列
【OpenCV 图像处理2】:OpenCV 基础知识
Matlab map with color representation module value size arrow
Pisanix v0.2.0 released | Added support for dynamic read-write separation
leetcode-另一棵树的子树
[Fortune-telling-60]: "The Soldier, the Tricky Way"-2-Interpretation of Sun Tzu's Art of War
lua学习
Note that Weifang generally needs to pay attention to issuing invoices
RAID磁盘阵列
Access Characteristics of Constructor under Inheritance Relationship
虚拟内存原理与技术