【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
相关推荐
羑悻的小杀马特1 小时前
PostgreSQL + Cpolar 组合拳,彻底打破局域网限制,远程访问数据库像本地一样简单
数据库·postgresql
松涛和鸣1 小时前
DAY61 IMX6ULL UART Serial Communication Practice
linux·服务器·网络·arm开发·数据库·驱动开发
二哈喇子!7 小时前
MySQL数据更新操作
数据库·sql
二哈喇子!7 小时前
MySQL命令行导入数据库
数据库·sql·mysql·vs code
心动啊1217 小时前
SQLAlchemy 的使用
数据库
夏鹏今天学习了吗8 小时前
【LeetCode热题100(92/100)】多数元素
算法·leetcode·职场和发展
学习中的DGR8 小时前
[GXYCTF2019]Ping Ping Ping 1和[SUCTF 2019]EasySQL 1新手解题过程
sql·安全·web安全·网络安全·php
曾经的三心草9 小时前
redis-2-数据结构内部编码-单线程-String命令
数据结构·数据库·redis
二哈喇子!9 小时前
基于SSM框架的公交车查询系统的设计与实现
java·数据库·ssm
Coder_Boy_9 小时前
基于SpringAI的在线考试系统-智能考试系统-学习分析模块
java·开发语言·数据库·spring boot·ddd·tdd