这是我的程序。
我如何才能添加另一个条件,该条件应满足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
最佳答案
如果您仅提及MySQL获得时间,即NOW()
您将获得差异介于0到60秒(1分钟)之间的记录
然后,您应该将此添加到您的程序中
AND (DriverLocation.updated_at - NOW() BETWEEN 0 AND 60 )
关于php - 添加另一个条件程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28568986/