当前位置:网站首页>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;
边栏推荐
- 特殊矩阵的压缩存储
- lua learning
- leetcode 15
- Opening - Open a new .NET modern application development experience
- matlab绘制用颜色表示模值大小的箭头图
- Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
- ARM Mailbox
- How to deal with your own shame
- 【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
- leetcode-另一棵树的子树
猜你喜欢
C language implements a simple number guessing game
虚拟内存原理与技术
VSCode Change Default Terminal how to modify the Default Terminal VSCode
Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit
What should I do if the self-incrementing id of online MySQL is exhausted?
基于左序遍历的数据存储实践
Programmer's list of sheep counting when insomnia | Daily anecdote
lua learning
【OpenCV 图像处理2】:OpenCV 基础知识
SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
随机推荐
ARM Mailbox
转:查尔斯·汉迪:你是谁,比你做什么更重要
Fragment visibility judgment
Semi-Decentralized Federated Learning for Cooperative D2D Local Model Aggregation
Quickly learn chess from zero to one
Matlab画图3
Go 微服务开发框架 DMicro 的设计思路
DAY23:命令执行&代码执行漏洞
【存储】曙光存储DS800-G35 ISCSI各映射LUN给服务器
力扣-相同的树
Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design
常见的硬件延迟
Error: Not a signal or slot declaration
Domain Driven Design - MDD
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
多线程(2)
Matlab map with color representation module value size arrow
网络安全与元宇宙:找出薄弱环节
LeetCode uses the minimum cost to climb the stairs----dp problem
回顾51单片机