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

MySQL View Principle Analysis

Table of contents Updatable Views Performance of ...

Sample code of uniapp vue and nvue carousel components

The vue part is as follows: <template> <...

Detailed explanation of how to manually deploy a remote MySQL database in Linux

1. Install mysql Run the following command to upd...

Three ways to communicate between Docker containers

We all know that Docker containers are isolated f...

Getting Started with Nginx Reverse Proxy

Table of contents Overview The role of reverse pr...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

A brief analysis of MySQL's lru linked list

1. Briefly describe the traditional LRU linked li...

How to use CSS to write different styles according to sub-elements

The effect we need to achieve: What is needed The...

Use javascript to create dynamic QQ registration page

Table of contents 1. Introduction 1. Basic layout...

React event binding details

Table of contents Class component event binding F...

CentOS6.8 Chinese/English environment switching tutorial diagram

1. Introduction People who are not used to Englis...

CocosCreator ScrollView optimization series: frame loading

Table of contents 1. Introduction 2. Analysis of ...

SVG+CSS3 to achieve a dynamic wave effect

A vector wave <svg viewBox="0 0 560 20&qu...