sql
复制代码
select
/*判断是否超时,时间是否大于当前时间*/
case when cc.OVERTIME > NOW() then '1' else '0' end as is_timeout,
/*计算分钟数*/
TIMESTAMPDIFF(MINUTE, cc.CREATE_TIME,cc.ARCHIVE_DATE) AS FLOW_TIME,
/*CASE处理字段为空或者空字符默认-1,其他等于原始值*/
CASE WHEN TPP.FLAG IS NULL THEN '-1' WHEN LENGTH(TPP.FLAG )=0 THEN '-1' ELSE TPP.FLAG END AS SHEET_TYPE,
/*CASE多个类型判断1 */
CASE cc.P_STATE when '70010004' or '70010006' then '1' ELSE '0' END as SHEET_STATUS,
/*CASE多个类型转换2 */
CASE cc.cont_level WHEN '一级' THEN '1' WHEN '二级' THEN '2' ELSE '3' END as sms_level,
/*如果为空默认填充-1;如果数值类型进行转换字符类型*/
IFNULL(CAST(cc.CONTENT AS CHAR),'-1') as cmplnt_desc,
/*时间格式化处理*/
DATE_FORMAT(ftr.SIGN_DATE,'%Y%m%d') as sent_date,
from table_name cc
WHERE 1=1
and cc.CREATE_DATE BETWEEN '2023-12-24 00:00:00' and '2023-12-26 00:00:00'