2

我有一个 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)
4

1 回答 1

2

去掉周围的撇号InTime,即

where geofence <>'' and InTime >  DATE_SUB(NOW(), INTERVAL 26 HOUR)
于 2013-03-22T13:32:23.100 回答