1.数据库背景MySQL:
使用以下函数,可以将对应的数字与中文进行一一对应。
同样一段内部含义的sql:
执行结果呈现的差异性:
sql编码如下:
Select
(case
when a.`Status` = 0 then '正常'
when a.`Status` = 1 then '故障'
else 'null'
end) as status,
(case
when b.`DiskStatus` = 0 then '硬盘正常'
when b.`DiskStatus` = 1 then '硬盘故障'
when b.`DiskStatus` = 255 then '离线'
when b.`DiskStatus` = 2 then '硬盘满'
when b.`DiskStatus` = 3 then '硬盘空闲'
when b.`DiskStatus` = 4 then '硬盘异常'
when b.`DiskStatus` = 5 then '硬盘热备'
when b.`DiskStatus` = 6 then '硬盘离线'
when b.`DiskStatus` = 7 then '硬盘重建'
when b.`DiskStatus` = 8 then '硬盘备份'
when b.`DiskStatus` = 9 then '硬盘移除'
when b.`DiskStatus` = 10 then '硬盘同步'
when b.`DiskStatus` = 11 then '硬盘休眠'
when b.`DiskStatus` = 12 then '硬盘失效'
when b.`DiskStatus` = 20 then '硬盘正常'
when b.`DiskStatus` = 21 then '硬盘离线'
when b.`DiskStatus` = 22 then '部分降级'
when b.`DiskStatus` = 23 then '降级'
when b.`DiskStatus` = 100 then '休眠硬盘出错'
when b.`DiskStatus` = 101 then '未连接硬盘'
when b.`DiskStatus` = 102 then '未格式化'
when b.`DiskStatus` = 103 then '硬盘正在格式化'
when b.`DiskStatus` = 104 then '不匹配'
when b.`DiskStatus` = 105 then 'SMART状态'
when b.`DiskStatus` = 106 then '虚拟磁盘可扩容'
when b.`DiskStatus` = 107 then '硬盘正在修复'
when b.`DiskStatus` = 108 then '硬盘正在等待格式化'
when b.`DiskStatus` = 109 then '硬盘已卸载'
when b.`DiskStatus` = 110 then '本地硬盘不存在'
when b.`DiskStatus` = 111 then '正在删除硬盘'
else 'null'
end )as DiskStatus,
(case
when b.`IsOnLine` = 2 then '离线'
when b.`IsOnLine` = 1 then '在线'
when b.`IsOnLine` = -1 then '缺省'
else 'null'
end) as IsOnLine
from device as a INNER JOIN devicerunstatus as b on a.DeviceNum=b.DeviceNum;
呈现结果如下:、
至此完成sql语句的翻译。