当前位置:网站首页>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;
边栏推荐
- Solve connect: The requested address is not valid in its context
- 【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
- C语言实现简单猜数字游戏
- nodeJs--encapsulate routing
- SuperMap支持的国产环境汇总
- 从零到一快速学会三子棋
- 线上MySQL的自增id用尽怎么办?
- 使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
- Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
- Images using redis cache Linux master-slave synchronization server hard drive full of moved to the new directory which points to be modified
猜你喜欢

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

The 2022 EdgeX China Challenge will be grandly opened on August 3

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

Flink 1.15.1 集群搭建(StandaloneSession)

js中try...catch和finally的用法

蚁剑高级模块开发
![[ROS] (10) ROS Communication - Service Communication](/img/4d/4657f24bd7809abb4bdc4b418076f7.png)
[ROS] (10) ROS Communication - Service Communication

DAY23: Command Execution & Code Execution Vulnerability

HOG feature study notes

DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
随机推荐
力扣-二叉树的前序遍历、中序遍历、后序遍历
继承关系下构造方法的访问特点
Access Characteristics of Constructor under Inheritance Relationship
树形查找(二叉查找树)
回顾51单片机
解决connect: The requested address is not valid in its context
Matlab画图3
树表的查找
Short domain name bypass and xss related knowledge
hypervisor相关的知识点
LPQ (local phase quantization) study notes
协作D2D局部模型聚合的半分散联合学习
ARM Mailbox
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
重新审视分布式系统:永远不会有完美的一致性方案……
post-study program
Pisanix v0.2.0 released | Added support for dynamic read-write separation
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
Matlab map with color representation module value size arrow