【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
相关推荐
FungLeo20 小时前
FengCMS · PHP+MySQL 升级实录· 回归测试从 69 项到 478 项:HTTP/数据库回归套件怎么搭
数据库·mysql·php·回归测试·fengcms
captain37620 小时前
Redis简单使用
数据库·redis·缓存
代码不停21 小时前
Redis基本数据类型
数据库·redis
aifannihao21 小时前
ON CONFLICT 冲突后返回空:sqlite3 实测 get-or-create
数据库·python·postgresql·sqlite3·标准库
两点王爷21 小时前
面试 | 索引是什么?有哪些分类?索引为什么会失效?
sql·面试
得物技术21 小时前
Computer Use与Browser Use:揭秘Agent如何操作电脑和浏览器|得物技术
数据库·github·ai编程
Navigator_Z21 小时前
LeetCode //C - 1320. Minimum Distance to Type a Word Using Two Fingers
c语言·算法·leetcode
小小程序员.¥21 小时前
mysql备份以及数据恢复实战
数据库·mysql
AllData公司负责人1 天前
实战一:AllData大模型与AI数据底座-数据传输平台-DBSyncer,搭建 File 到 Doris 高效数据同步链路,批量文件离线入仓
数据库·人工智能·分布式·大模型·数据传输·数据同步·连接器
黄俊懿1 天前
【架构师从入门到进阶】第七章:缓存和存储的优化思路——第六节:数据库更新和缓存更新的组合方案
数据库·缓存·性能优化·架构·系统架构