这是我的程序..
如何添加另一个条件,该条件应满足driver_latlong表中的updated_time记录应小于1分钟?
这是我的程序
BEGIN
SET @sql = CONCAT(
'SELECT (DriverLocation.updated_at - NOW()) as Diff, DriverLocation.updated_at, NOW(), DriverLocation.AutoId, DriverLocation.DriverId,
@dist:= ( 6371 * acos( cos( radians(',lat,') ) * cos( radians( DriverLocation.Lat ) ) * cos( radians( DriverLocation.Long ) - radians(',lng,') ) + sin( radians(',lat,') ) * sin( radians( DriverLocation.Lat ) ) ) ) AS distance
FROM driver_latlong DriverLocation LEFT JOIN driver_details DriverDetail on DriverDetail.DriverId = DriverLocation.DriverId where DriverLocation.DriverId NOT IN (',Exclude,') AND DriverDetail.IsActive=',1,' AND DriverDetail.IsOnline=',1,' having distance <=50000.0 ORDER BY distance ASC LIMIT 0 , 1;');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
答案 0 :(得分:0)
如果您只是参考MySQL获得的时间,即NOW()
您将获得差异介于0到60秒(1分钟)
之间的记录然后您应该将此添加到您的程序
AND (DriverLocation.updated_at - NOW() BETWEEN 0 AND 60 )