mysql case, if

if语句:

用法和excel的if函数很像

if(expr1, value_if_expr1_is_true, value_if_expr1_is_false)

select if(tag = 3, 3, 0) as tag from database_name.table_name;  # if tag = 3, set tag = 3, else set tag = 0

case 语句

select case tag when 3 then 3 else 0 end as tag from database_name.table_name;  # when tag = 3, set tag = 3, else set tag = 0

原文地址:https://www.cnblogs.com/buxizhizhoum/p/7880050.html