语法1:
- case sex
- when '1' then '男'
- when '2' then '女’
- else '其他'
- end
语法2:
- case
- when sex = '1' then '男'
- when sex = '2' then '女'
- else '其他'
- end
eg:1393. 股票的资本损益 - 力扣(LeetCode)
- select
- stock_name,
- sum(
- case operation
- when 'Buy' then -price
- else price
- end
- ) as capital_gain_loss
- from Stocks
- group by stock_name;
- update Salary
- set sex =
- case sex
- when 'f' then 'm'
- else 'f'
- end;