In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces MySQL to explain the conditional judgment function example, has a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.
Function:
IF(expr,v1,v2) function
(2)IFNULL(v1,v2) function
â-o January (3)
(Related free learning recommendation: mysql video tutorial)
(1)if(expr,v1,v2) function
In the if(expr,v1,v2) function, return v1 if expr is true(expr0 and eprnull), otherwise return v2.
[Example] Use the if() function to make conditional judgments. The SQL statement is as follows:
mysql> select if(1>2,2,3), -> if(1 if(strcmp('test','test1'),'no','yes');+-------------+--------------------+---------------------------------------+| if(1>2,2,3) | if(1 select ifnull(1,2),ifnull(null,10),ifnull(1/0,'wrong');+-------------+-----------------+---------------------+| ifnull(1,2) | ifnull(null,10) | ifnull(1/0,'wrong') |+-------------+-----------------+---------------------+| 1 | 10 | wrong |+------------------------------------------+1 row in set (0.00 sec)(3)case function
1.case expr when v1 then r1 [ when v2 then r2] [else rn] end
This function says that if expr is equal to vi, it returns the result after then, and if expr is not equal to all values, it returns m after else.
[Example] Use case value when statement to execute branch operation. SQL statement is as follows:
mysql> select case 2 when 1 then 'one' when 2 then 'two' else 'more' end;+------------------------------------------------------------+| case 2 when 1 then 'one' when 2 then 'two' else 'more' end |+------------------------------------------------------------+| two |+------------------------------------------------------------+1 row in set (0.00 sec)
2.case when v1 then rv [when v2 then r2] else rn] end
This function indicates that if a vi value is true, it returns the result after the corresponding position then, and if all values are not true, it returns rn after else.
The default return value type of a case expression is any compatible set type of return values, depending on the context.
[Example] Use case when statement to execute branch operation. SQL statement is as follows:
mysql> select case when 1
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.