mysql语法_case_when_then

case when 条件1 and 条件2
     then 条件成立业务语句
     else 条件不成立业务语句
end

例子一
select 
    case when id>5
             then '大数'
             else '小数'
    end as 'aaa'
from t_goods;
例子二 也可以用于update语句
<update id="updateGroupOrderAfterOrderExpired">
    update t_group_order
    set state= case when expire_time &lt; now() 
                    then '${@[email protected]}'
                    else state end
    where id = #{groupOrderId} ;
</update>

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/83276275