Home >Database >Mysql Tutorial >Is there if in mysql?

Is there if in mysql?

WBOY
WBOYOriginal
2022-06-15 15:22:323419browse

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)".

Is there if in mysql?

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

Is there if in mysql?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use mysql locate()Next article:How to use mysql locate()