【SQL】1873. 计算特殊奖金(CASE WHEN;IF())

题目描述

leetcode题目:1873. 计算特殊奖金


Code

写法一: CASE WHEN

sql 复制代码
select employee_id, 
    (case when employee_id % 2 = 0 or name like 'M%' then salary = 0 else salary end) as bonus
from Employees
order by employee_id

写法二 :IF()

sql 复制代码
select employee_id, 
    if(employee_id % 2 = 0 or name like 'M%', 0, salary) as bonus
from Employees
order by employee_id
相关推荐
smallyoung17 小时前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
parade岁月17 小时前
MySQL JOIN解析:朴实无华但食之有味
数据库·后端
用户31693538118317 小时前
MySQL服务无法启动问题解决全记录
数据库
vivo互联网技术21 小时前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
倔强的石头_1 天前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库
SelectDB2 天前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
jiayou643 天前
KingbaseES 表级与列级加密完全指南
数据库·后端
GBASE4 天前
G术时刻 |GBase 8s数据库事务并发控制之封锁技术介绍(下)
数据库
xiezhr4 天前
逛GitHub发现了一款免费的带AI功能的数据库管理工具
数据库·ai编程·dba
To_OC4 天前
LC 207 课程表:刚学图论那会儿,我连这是拓扑排序都没看出来
javascript·算法·leetcode