Home >Database >Mysql Tutorial >Is there if in mysql?
There is the if() function in mysql; the if() function can be used to determine conditions, returning a value when the condition is true, and returning another value when the condition is false. The syntax is "IF(condition, The return value when the condition is true, the return value when the condition is false)".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Is there if in mysql
The IF() function returns a value when the condition is TRUE, if the condition is FALSE then returns another value.
Syntax
IF(condition, value_if_true, value_if_false)
condition is required. The value to test
value_if_true Optional. The value to return condition is true
value_if_false Optional. The value condition to be returned is false
The example is as follows:
IF(expr1,expr2,expr3);
If expr1 is TRUE, the return value of IF() is expr2, otherwise the return value is expr3
update salary set sex =if(sex = '男','女','男') #这是leetcode上的一道题,将salary表中的性别进行转换,男变女,女变男
Recommended learning: mysql video tutorial
The above is the detailed content of Is there if in mysql?. For more information, please follow other related articles on the PHP Chinese website!