当前位置:网站首页>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;
边栏推荐
- DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
- 多线程(2)
- 使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
- [LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
- hypervisor相关的知识点
- Using OpenVINO to implement the flying paddle version of the PGNet inference program
- Flink 1.15.1 集群搭建(StandaloneSession)
- lua learning
- STM32使用stm32cubemx LL库系列教程
- 网络安全与元宇宙:找出薄弱环节
猜你喜欢

Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design

Pisanix v0.2.0 released | Added support for dynamic read-write separation

Programmer's list of sheep counting when insomnia | Daily anecdote

程序员失眠时的数羊列表 | 每日趣闻

The design idea of DMicro, the Go microservice development framework

SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型

View handler stepping record

【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?

使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号

Access Characteristics of Constructor under Inheritance Relationship
随机推荐
View handler stepping record
matlab绘制用颜色表示模值大小的箭头图
SuperMap支持的国产环境汇总
散列表的查找(哈希表)
[深入研究4G/5G/6G专题-51]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-11-高可靠性技术-2-链路自适应增强(根据无线链路状态动态选择高可靠性MCS)
Matlab画图3
C student management system Find student nodes based on student ID
C语言日记 9 if的3种语句
HOG feature study notes
hypervisor相关的知识点
iNFTnews | What can NFTs bring to the sports industry and fans?
02 [Development Server Resource Module]
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
【 2 】 OpenCV image processing: basic knowledge of OpenCV
Gantt chart is here, project management artifact, template is used directly
What should I do if the self-incrementing id of online MySQL is exhausted?
[Fortune-telling-60]: "The Soldier, the Tricky Way"-2-Interpretation of Sun Tzu's Art of War
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
.Net C# 控制台 使用 Win32 API 创建一个窗口