1、Mysql中IF表达式使用
IF(expr1,expr1,expr1)
如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。IF() 的返回值为数字值或字符串值,具体情况视其所在语境而定。
2、IFNULL(expr1,expr2)
假如expr1 不为 NULL,则 IFNULL() 的返回值为 expr1; 否则其返回值为 expr2。IFNULL()的返回值是数字或是字符串,具体情况取决于其所使用的语境
3、mysql中使用自定义变量
-------------------在sql语句中使用用户自定义的变量-----------------
--将select列值赋予变量
select @class_id := id from t_classes where id = 2;
delete from t_student where classesid = @class_id;
delete from t_classes where id = @class_id;
--将表达式至赋予变量
select @max_limbs := max(arms+legs) from limbs;
--将含有auto_increment列的表插入新行之后的last_insert_id()的结果赋给变量
select @last_id := last_insert_id();