mysql in the case when then end the meaning and usage

See this blog: https://blog.csdn.net/rongtaoup/article/details/82183743
Case End the when the then the else statement is used to check on the status meet a variety of conditions, similar to java in if ... else, there is used to turn the row of columns the query, this is on the back of the select clause is to act as the role of the field.
Specific usage is: divided into two types, one is the simple functional form, is another form of expression.
Explain their meaning:
a simple form of the function
case when value field then results otherwise else end;

Forms of expression
case when field = value (in this written expression, for example, score = 80) then the results of other circumstances else end;

简单的函数形式
select case score when 'a' then '优秀' else '良好' end from student;

表达式形式
select case when  score between and 90  then '优秀' else '良好' end from student;

In the case of complex usage which can also be nested subqueries.
case when a field as it can, in fact, later out of a need, select field, its aggregation function may be used, alias, de-duplication, and other operations.

Guess you like

Origin www.cnblogs.com/jasonboren/p/11575476.html