Mysql:IFNULL的使用说明

IFNULL(expr1,expr2)

如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2。

IFNULL()返回一个数字或字符串值

具体用法如:现有学生表(tbl_student)和分数表(score),查询学生表的所有字段和学生相对于的英语成绩(english_score)sql如下:

select stu.*,IFNULL(score.english_score,0) from tbl_student stu,tbl_score score where stu.stu_id=score.stu_id

以上sql中,如果score表中的english_score有值,则IFNULL(score.english_score,0)就显示english_score,否则,显示0

原文地址:https://www.cnblogs.com/wodexk/p/10711551.html