IFNULL(expr1,expr2)

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

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

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

具体用法如:现有学生表(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

,

如果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

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄