MySQL case when group by example

MySQL case when group by example

A mysql-like php switch case statement.

  1. select xx field,
  2. Case Field
  3. when condition 1 then value 1
  4. when condition 2 then value 2
  5. else other value END alias
  6. from table name;

Here is an example of group summation:

select sum(redpackmoney) as stota,ischeck 
from t_redpack
group 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_redpack
group by isCheck

In checkinfo, -1, 0, 1 are replaced with checkfalse, uncheck, checktrue (CASE WHEN performs string replacement processing)

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

You may also be interested in:
  • MySQL case when usage example analysis
  • Detailed example of using case statement in MySQL stored procedure
  • Example of using CASE WHEN in MySQL sorting
  • In-depth analysis of the Identifier Case Sensitivity problem in MySQL
  • Detailed explanation of Mysql case then usage
  • mysql update case update field value is not fixed operation

<<:  Vue implements simple data two-way binding

>>:  How to start tomcat using jsvc (run as a normal user)

Recommend

10 Best Practices for Building and Maintaining Large-Scale Vue.js Projects

Table of contents 1. Use slots to make components...

JavaScript CollectGarbage Function Example

First, let's look at an example of memory rel...

Implementation of deploying Apollo configuration center using docker in CentOS7

Apollo open source address: https://github.com/ct...

Implementation of multiple instances of tomcat on a single machine

1. Introduction First of all, we need to answer a...

Unzipped version of MYSQL installation and encountered errors and solutions

1 Installation Download the corresponding unzippe...

Detailed explanation based on event bubbling, event capture and event delegation

Event bubbling, event capturing, and event delega...

Summary of MySql storage engine and index related knowledge

Storage Engine What is a database storage engine?...

Detailed explanation of important cascading concepts in CSS

Recently, I encountered a problem in the process ...

Set an icon for the website to be displayed on the far left of the browser tab

What is the purpose of this sentence? Copy code Th...

MySQL download and installation details graphic tutorial

1. To download the MySQL database, visit the offi...

A Brief Analysis of the Differences between “:=” and “=” in MySQL

= Only when setting and updating does it have the...

Detailed explanation of how two Node.js processes communicate

Table of contents Preface Communication between t...

Detailed explanation of docker version es, milvus, minio startup commands

1. es startup command: docker run -itd -e TAKE_FI...

Example usage of JavaScript tamper-proof object

Table of contents javascript tamper-proof object ...