sql casewhen的使用实例
| id | zdname |
|---|---|
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
表名: table
要求把表中的a输出为’黑’ b输出为’白’ c输出为’红’ d输出为’蓝’
语句如下: select case when zdname = ‘a’ then ‘黑’
when zdname = ‘b’ then ‘白’
when zdname = ‘c’ then ‘红’
else ‘蓝’ end
from ‘table’ ;
sql casewhen的使用实例
| id | zdname |
|---|---|
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
表名: table
要求把表中的a输出为’黑’ b输出为’白’ c输出为’红’ d输出为’蓝’
语句如下: select case when zdname = ‘a’ then ‘黑’
when zdname = ‘b’ then ‘白’
when zdname = ‘c’ then ‘红’
else ‘蓝’ end
from ‘table’ ;