数据库
首页 > 数据库> > MySQL中CASE WHEN用法

MySQL中CASE WHEN用法

作者:互联网

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 

 

详情见菜鸟教程高级函数教程

上图是从查询结果中进行判断运算,返回一个单独的列的值 

标签:CASE,areacode,MySQL,WHEN,dispatch,acceptTime,user,time
来源: https://www.cnblogs.com/san1/p/15594890.html