Detailed explanation of mysql case when group by examples
A php switch case-like statement in mysql.
Select xx field, case field when condition 1 then value 1when condition 2 then value 2else other values END alias from table name
The following is an example of grouping 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
Replace-1,0,1 in checkinfo with checkfalse, uncheck, checktrue (CASE WHEN performs string replacement processing)
The above is a simple example of the use of case when statements in mysql.