MySql常用(三、流程和其他)函数
5.4流程函数
select id, if(is_check_in = '1', CONCAT(name, ':Need'), CONCAT(name, ':Not')) as CheckIn FROM t_conf_visit_task where is_delete = '0' and name is not null order by id asc limit 0, 5;select id, ifnull(is_user, 0) as user FROM t_conf_visit_task where is_delete = '0' order by id asc limit 0,5;
CASEWHEN expr1 THEN result1WHEN expr2THEN result2......ELSE [result]END当满足条件expr[1、2、3...]时,返回对应的result,否则返回ELSE后的result。
select plan_id, casewhen interval_type = '1'then '每日' when interval_type = '2'then '每周' when interval_type = '3'then '每月' else '自定义'end as '目标时间间隔'from t_visit_planwhere is_delete = '0' order by plan_id asc limit 0,5;
CASE expr WHEN value1 THEN result1 WHEN value2THEN result2......ELSE [default] END 当满足条件expr = value[1、2、3...]时,返回对应的result,否则返回ELSE后的result。
select plan_id, case interval_type when '1' then '每日' when '2' then '每周'when '3' then '每月' else '自定义'end as '目标时间间隔'from t_visit_planwhere is_delete = '0' order by plan_id asc limit 0,5;