SQL 1873 Calculate Special Bonus
2022/9/14 2:18:24
本文主要是介绍SQL 1873 Calculate Special Bonus,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Table: Employees
+-------------+---------+ | Column Name | Type | +-------------+---------+ | employee_id | int | | name | varchar | | salary | int | +-------------+---------+
employee_id
is the primary key for this table.
Each row of this table indicates the employee ID, employee name, and salary.
Write an SQL query to calculate the bonus of each employee. The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee name does not start with the character 'M'. The bonus of an employee is 0 otherwise.
Return the result table ordered by employee_id.
Solution
第一点需要按照 \(id\) 排序,用\(ORDER\ BY\)
对于判断条件,我们用 \(IF\) ,当条件为真时,为表达式2;否则为表达式3
点击查看代码
# Write your MySQL query statement below SELECT employee_id, IF (employee_id%2 AND name NOT LIKE "M%", salary, 0) AS bonus FROM Employees ORDER BY employee_id;
这篇关于SQL 1873 Calculate Special Bonus的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27文件掩码什么意思?-icode9专业技术文章分享
- 2024-12-27如何使用循环来处理多个订单的退款请求,代码怎么写?-icode9专业技术文章分享
- 2024-12-27VSCode 在编辑时切换到另一个文件后再切回来如何保持在原来的位置?-icode9专业技术文章分享
- 2024-12-27Sealos Devbox 基础教程:使用 Cursor 从零开发一个 One API 替代品 审核中
- 2024-12-27TypeScript面试真题解析与实战指南
- 2024-12-27TypeScript大厂面试真题详解与解析
- 2024-12-26怎么使用nsenter命令进入容器?-icode9专业技术文章分享
- 2024-12-26导入文件提示存在乱码,请确定使用的是UTF-8编码怎么解决?-icode9专业技术文章分享
- 2024-12-26csv文件怎么设置编码?-icode9专业技术文章分享
- 2024-12-25TypeScript基础知识详解