我有一個MySQL查詢,有幾個嵌套的選擇。該如下:mysql - 排序與嵌套選擇的非法混合
我內心的查詢,返回兩列:
` MIN(PreQuery.updatetime) as InTime`
`MAX(PreQuery.updatetime) as OutTime`
這些都是datetime格式,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)
對於開始,你可以做的是設置在查詢中的每個表相同的排序規則。 – 2013-03-22 13:31:00
謝謝,但只有一個表被引用。 – Smudger 2013-03-22 13:35:04