Case-when usage in Mysql

Source: Internet
Author: User

In a SELECT statement query, you can make a judgment that is similar to if else by using case when to query the results.

The specific usage

1.

SELECT a.website_id, B.customer_name, A.website_enddate, C.member_name, d.websitetype_id,
Case
When D.websitetype_id=1 then 400
When d.websitetype_id=2 then 400
When d.websitetype_id=12 then 5800
When d.websitetype_id=13 then 5800
When d.websitetype_id=13 then 5800
END as Money

From ...

2.

SELECT a.website_id, B.customer_name, A.website_enddate, C.member_name, d.websitetype_id,
Case d.websitetype_id

When 1 then 400
When 2 then 400
When 5800
When 5800
When 5800
END as Money

From ...

3. A simple if judgment

The IF (Judgment statement, true return value, False value returned) uses the same location as the case-when position, the syntax is simple, a bit like the ternary operation in PHP.


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.