今天在一个项目中的sql语句中看见了”case when”
网上搜了一下
--简单case函数
case sex
when '1' then '男'
when '2' then '女’
else '其他' end
--case搜索函数
case when sex = '1' then '男'
when sex = '2' then '女'
else '其他' end
项目中的语句是
select case when ti.topState is null then 0 else ti.topState end
数据库陌生但java熟悉
此语句相当于
select
case when ti.topState is null -> if(ti.topState == null) {
then 0 -> ti.topState = 0
else ti.topState end -> }else{ti.topState}
学习了。记录一下