Case has two formats. Simple case function and case search function.
--Simple case function Sexwhen ' 1 ' then ' Male ' when ' 2 ' then ' women ' else ' other ' end--case search function case when sex = ' 1 ' Then ' man ' when sex = ' 2 ' Then ' Women ' Else ' other ' END
In both of these ways, the same functionality can be achieved. The simple case function is relatively concise, but there are some limitations in function, such as write-judgement, compared to the search function.
There is also a problem to be aware that the case function returns only the first qualifying value, and the remaining case section is automatically ignored.
--for example, the following SQL, you can never get the result of a "second class" When the case is col_1 in (' A ', ' B ') then ' first Class ' When col_1 in (' a ') then ' second ' else ' other ' END
Transferred from: http://www.cnblogs.com/yazdao/archive/2009/12/09/1620482.html
SQL in the query statement to add judgment, control the output of the content