当前位置:网站首页>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;
边栏推荐
- 编译预处理等细节
- SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
- View handler 踩坑记录
- Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
- leetcode 15
- The 20th day of the special assault version of the sword offer
- 学习笔记-----左偏树
- 使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
- 1873. 计算特殊奖金
- LeetCode uses the minimum cost to climb the stairs----dp problem
猜你喜欢

Regular expression to match a certain string in the middle

Matlab画图3

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

2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from

Unleashing the engine of technological innovation, Intel joins hands with ecological partners to promote the vigorous development of smart retail

Tree search (bintree)

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

树表的查找

没有对象的程序员如何过七夕

QT语言文件制作
随机推荐
【 2 】 OpenCV image processing: basic knowledge of OpenCV
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
【C语言】详解栈和队列(定义、销毁、数据的操作)
如何模拟后台API调用场景,很细!
特殊矩阵的压缩存储
数据增强Mixup原理与代码解读
The design idea of DMicro, the Go microservice development framework
C language diary 9 3 kinds of statements of if
std::string::find 返回值的坑
Note that Weifang generally needs to pay attention to issuing invoices
[ROS] (10) ROS Communication - Service Communication
Using OpenVINO to implement the flying paddle version of the PGNet inference program
C语言日记 9 if的3种语句
树表的查找
CPDA|运营人如何从负基础学会数据分析(SQL)
回顾51单片机
Error: Not a signal or slot declaration
Quickly learn chess from zero to one
2022-08-04:输入:去重数组arr,里面的数只包含0~9。limit,一个数字。 返回:要求比limit小的情况下,能够用arr拼出来的最大数字。 来自字节。
没有对象的程序员如何过七夕