If statement in MySQL

Source: Internet
Author: User
Ifnull (expr1, expr2), if expr1 is not null, ifnull () returns expr1, otherwise it returns expr2. Ifnull () returns a number or string value, depending on the context in which it is used. Mysql> select ifnull (1/0);-> 1 mysql> select ifnull ();-> 0 mysql> select ifnull (, 10 ); -> 10 mysql> select ifnull (1/0, 'yes');-> 'yes' if (expr1, expr2, expr3) if expr1 is true (expr1 <> 0 and expr1 <> null), if () returns expr2; otherwise, expr3 is returned. If () returns a number or string value, depending on the context in which it is used. Mysql> select if (1> 2, 2, 3);-> 3 mysql> select if (1 <2, 'yes', 'no '); -> 'yes' mysql> select if (strcmp ('test', 'test1'), 'yes', 'no');-> 'no'

 

 

The following statements are correct and have been tested:

Select if (event <= 2, 'hahaha', event) from cti_workevent limit; select ifnull (event, 'Kong ') from cti_workevent limit; select if (event <= 2, if (event = 1, 'haha11', 'haha22'), event) from cti_workevent limit 0, 10;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.