SQL decode函数

  1. 格式

    select decode(columname,值1,翻译值1,值2,翻译值2,...,值n,翻译值n,缺省值)   

    from tablename

    where...

  其中:缺省值可以是column name本身,也可以是自定义的值,如other


  功能:相当于if语句,将查询结果翻译为其他值

  2.  举例

若sale值=1000时翻译为D,=2000时翻译为C,=3000时翻译为B,=4000时翻译为A,如是其他值则翻译为Other:

Select monthid , decode (sale,1000,'D',2000,'C',3000,'B',4000,'A',’Other’) sale from output
原文地址:https://www.cnblogs.com/qijiujiu/p/13254771.html