MySQL functions IF(expr1 , expr2 , expr3) and IFNULL(expr1 , expr2)

IF(expr1 , expr2 , expr3)

The value of expr1 is TRUE, the return value is expr2 

The value of expr1 is FALSE, the return value is expr3

SELECT IF (1 >= 2, 'xx', 'yy')  -- yy

IFNULL(expr1 , expr2)

If the value of expr1 is NULL, return expr2

If the value of expr1 is not NULL, return expr1

SELECT IFNULL(NULL,'yy')  -- yy

SELECT IFNULL('xx','yy')   -- xx

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325855619&siteId=291194637