Reprint please specify the source:
The simple case statement only allows you to match the value of an expression to a different set of values. In order to perform more complex matches, such as scopes, you can use the searchable case statement.
A searchable case statement is equivalent to an if statement, but its construction is more readable. The following instructions can be used to search the syntax of a case statement:
Case
When condition_1 then commands
When condition_2 then commands
...
ELSE commands
END case;
MySQL evaluates each condition in the evaluate when clause until it finds a condition with a value of true, and then executes the corresponding command (commands) in the then clause.
If no condition is true, the command in the ELSE clause is executed (commands). If you do not specify an ELSE clause, and no condition is true,mysql, an error message is issued.
Instance:
SELECT Case U.playertype when'1'Then U.num ELSE0END as'Liveplaycount', Case U.playertype when'2'Then U.num ELSE0END as'Vodplaycount', Case U.playertype when'1'Then U.flownum ELSE0END as'Liveflow', Case U.playertype when'2'Then U.flownum ELSE0END as'Vodflow',0As'Storespace' , 0As'Storeresiduespace'From (SELECT playertype, COUNT (*) as NUM, Ifnull (SUM (bytessend),0) as'Flownum'From tbl_player_statistics WHERE playertime between CONCAT (Date_format (#{month},'%y-%m'),'-01 00:00:00') and CONCAT (Date_format (Last_day (#{month}),'%y-%m-%d'),'23:59:59') GROUP by Playertype)
Case usage in MySQL