Mysql case when group by instance details, mysqlcase

Source: Internet
Author: User
Tags php switch switch case

Mysql case when group by instance details, mysqlcase

Similar to the php switch case statement in mysql.

  1. Select xx field,
  2. Case Field
  3. When condition 1 then value 1
  4. When condition 2 then value 2
  5. Other else value END alias
  6. From table name;

The following is an example of group summation:

Select sum (redpackmoney) as stota, ischeck from t_redpackgroup by isCheck

Use case when:

Select sum (redpackmoney) as stota, (CASE isCheck WHEN '1' then' checktrue 'when '0' THEN 'uncheck' when'-1 'then' checkfalse 'else 'unknow' END) as checkinfo from t_redpackgroup by isCheck

In checkinfo, replace-1, 0, and 1 with checkfalse, uncheck, and checktrue (case when for string replacement)

The above is a simple example of the case when statement in mysql.

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.