- select col1, col2,
- case
- when col3 > 1 and col3 <2
- then '1'
- when col3 > 2 and col3 <3
- then '2'
- when col3 > 3 and col3 <4
- then '3'
- else '4'
- end mycol
- from table1
注意点:
1、以case开头,以end结尾;
2、分支中when后跟条件,then为显示结果;
3、else为除此之外的默认情况,类似于高级语言程序中switch case的default,可以不加;
4、end后跟别名。