MySQL in the case when else end usage

 

Ends with the beginning of the case end

1, case when condition 1 then the value of the value of end 1 else does not satisfy the conditions

2, case when condition value field then the result satisfies the condition does not satisfy the end condition results else

Result 3, case when the result of the conditional expression satisfying the condition 1 then 1 else does not satisfy the conditions of 1

    when the result of the conditional expression satisfying the condition 2 then 2 else the result does not satisfy the conditions of 2 end

 Both methods 1 and 2, can achieve the same functionality. Case wording simple function is relatively simple, but Case and search function compared to functional aspects will be some restrictions, such as writing predicate.
There is also a need to pay attention to the problem, Case function returns only the first matching value, the rest of the Case section will be automatically ignored.

 -------------------------------------------------- ----------------- gorgeous dividing line ----------------------------- -------------------------------------------------- -------------------------------

 students table data

Use a:

 Usage II.

 Usage III.

 

 

Guess you like

Origin www.cnblogs.com/gxfaxe/p/10956737.html