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 1=1 and stu.stu_id=score.stu_id

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

猜你喜欢

转载自blog.csdn.net/weixin_40101530/article/details/84403281