格式:
 order by decode([字段名],字段值1,‘替换值1’,字段值2,‘替换值2’,字段值3,‘替换值3’,)
 即如果字段值符合【字段值1】,则替换为【替换值1】以此类推
举例:根据职务指定排序
select * from ioc_rcsdb.a_zb_zwfw_zbzs
where zbsj='2021-12-03'
order by decode(zw,'应急值班员','1','区值班长','2')
 
返回结果
 
 没有定义排序的会乱序排,如“区带班员”
延申——
 decode函数更多也用来判断数据是否匹配,或者替换值
select zw,decode(zw,'应急值班员','1','区值班长','2','aaa','3') as name 
from ioc_rcsdb.a_zb_zwfw_zbzs
where zbsj='2021-12-03'
 











