我有这个查询:
set @last_uid = 0;
set @last_tm = '00:00';
set @last_vid = 0;
SELECT v.*,
CASE WHEN @last_uid = visitorid AND cast( @last_tm as datetime) >= subtime( timestamp, '01:00' )
THEN
if( (@last_tm := timestamp ), @last_vid, @last_vid)
ELSE
if( (@last_uid := visitorid) + (@last_vid := @last_vid+1) +(@last_tm := timestamp ),@last_vid, @last_vid )
END AS newVisitID
FROM visits v
ORDER BY timestamp DESC, visitorid
我尝试在 WHERE 子句中使用 newVisitID 列,如下所示:
WHERE newVisitID <=5
这给了我错误:
#1054 - Unknown column 'newVisitID' in 'where clause'
谁能帮我解决这个问题?