select dispatch_user_time,dispatch_areacode_time,acceptTime,last_update_time,distTime, CASE WHEN (TIMESTAMPDIFF(HOUR,dispatch_areacode_time,dispatch_user_time)-acceptTime) >0 THEN '超时' WHEN (TIMESTAMPDIFF(HOUR,dispatch_areacode_time,dispatch_user_time)-acceptTime) <0 THEN '未超时' ELSE '' END accept, CASE WHEN (TIMEDIFF(last_update_time,ADDDATE(dispatch_areacode_time,INTERVAL distTime DAY))) > 0 THEN '超时' WHEN (TIMEDIFF(last_update_time,ADDDATE(dispatch_areacode_time,INTERVAL distTime DAY))) < 0 THEN '未超时' ELSE '' END investigate FROM test1
详情见菜鸟教程高级函数教程
上图是从查询结果中进行判断运算,返回一个单独的列的值