• 该表的所有数据


1. case when 条件 then 条件成立返回该结果 else 条件不成立返回该结果 end

# select case when 条件 then 条件成立返回该结果 else 条件不成立返回该结果 end as 别名 from 表名

select name, case when age < 20 then 0 else age end as age from t1;


2. if(条件, 条件成立返回该结果, 条件不成立返回该结果) -> 类似于三元表达式

# select if(条件, 条件成立返回该结果, 条件不成立返回该结果) as 别名 from 表名;

select name, if(age < 20, 0, age) as age from t1;