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

CentOS6.9+Mysql5.7.18 source code installation detailed tutorial

CentOS6.9+Mysql5.7.18 source code installation, t...

Example code for implementing an Upload component using Vue3

Table of contents General upload component develo...

Differences between MySQL MyISAM and InnoDB

the difference: 1. InnoDB supports transactions, ...

Steps for Django to connect to local MySQL database (pycharm)

Step 1: Change DATABASES in setting.py # Configur...

17 404 Pages You'll Want to Experience

How can we say that we should avoid 404? The reas...

CSS implements the web component function of sliding the message panel

Hello everyone, I wonder if you have the same con...

How to use Typescript to encapsulate local storage

Table of contents Preface Local storage usage sce...

mysql 5.7.17 winx64.zip installation and configuration method graphic tutorial

Preface: I reinstalled win10 and organized the fi...

UDP simple server client code example

I won’t go into details about the theory of UDP. ...

Join operation in Mysql

Types of joins 1. Inner join: The fields in the t...

HTML Tutorial: title attribute and alt attribute

XHTML is the basis of CSS layout. jb51.net has al...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

Examples of preview functions for various types of files in vue3

Table of contents Preface 1. Preview of office do...

Sample code for implementing music player with native JS

This article mainly introduces the sample code of...

Download MySQL 5.7 and detailed installation diagram for MySql on Mac

1. Enter the following address in the browser htt...