一. 查询的数字转换为中文返回前端
1. 如果是0或1表状态等,可用:
IF(字段 = 0, '否', '是') AS xxx
2. 如果是多个值,比如1,2,3可用:
ELT(字段, '计划治理', '正在治理', '治理完成') AS xxx // 如果字段等于1返回第一位结果'计划治理' , 等于2返回第二位,以此类推,如果小于等于0返回null
3. 还可用case语句,如:
CASE status WHEN 0 THEN '正常' WHEN 1 THEN '维护中' ELSE '水位低' END
复杂判断:
(CASE WHEN flowRate=0 AND liquidLevel=0.04 THEN 0 WHEN flowRate>0 AND liquidLevel=0.04 THEN '<0.04' ELSE liquidLevel END) liquidLevel
二. 查询的时间格式化后返回前端
1. 可用DATE_FORMAT进行日期格式化,如:
DATE_FORMAT(dateTime, "%Y-%m-%d %H:%i:%S") AS dateTime