【问题标题】:mysql - illegal mix of collations with nested selectsmysql - 排序规则与嵌套选择的非法混合
【发布时间】:2013-03-22 13:29:07
【问题描述】:

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

【问题讨论】:

  • 首先,您可以在查询中的每个表上设置相同的排序规则。
  • 谢谢,但只引用了一张表。

标签: mysql collation


【解决方案1】:

去掉InTime周围的撇号,即

where geofence <>'' and InTime >  DATE_SUB(NOW(), INTERVAL 26 HOUR)

【讨论】:

    猜你喜欢
    • 2012-08-28
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 2012-12-13
    • 2017-10-19
    • 2019-04-10
    相关资源
    最近更新 更多