我有一个MySQL查询,有一些嵌套选择。如下:
我的内部查询,返回两列:
` MIN( PreQuery.updatetime ) as InTime`
`MAX( PreQuery.updatetime ) as OutTime`
这些格式为日期时间格式2013-03-22 12:04:06
我想在过去26小时内只返回日期时间,所以请使用where子句:
'InTime'> DATE_SUB(NOW(), INTERVAL 26 HOUR)
这会返回错误:
#1267 - Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,NUMERIC) for operation '>'
有关如何更正或仅显示过去26小时数据的任何想法?一如既往地谢谢。
select * from (select
PreQuery.callingname,
PreQuery.geofence,
PreQuery.GroupSeq,
MIN( PreQuery.`updatetime` ) as InTime,
MAX( PreQuery.`updatetime` ) as OutTime
from
( select
v_starting.callingname,
v_starting.geofence,
v_starting.`updatetime`,
@lastGroup := @lastGroup + if( @lastAddress = v_starting.geofence
AND @lastVehicle = v_starting.callingname, 0, 1 ) as GroupSeq,
@lastVehicle := v_starting.callingname as justVarVehicleChange,
@lastAddress := v_starting.geofence as justVarAddressChange
from
v_starting,
( select @lastVehicle := '',
@lastAddress := '',
@lastGroup := 0 ) SQLVars
order by
v_starting.`updatetime` ) PreQuery
Group By
PreQuery.callingname,
PreQuery.geofence,
PreQuery.GroupSeq) parent
where geofence <>'' and 'InTime'> DATE_SUB(NOW(), INTERVAL 26 HOUR)
答案 0 :(得分:2)
删除InTime
周围的撇号,即
where geofence <>'' and InTime > DATE_SUB(NOW(), INTERVAL 26 HOUR)