表格中的两列 cityWalkStartTime 和 cityWalkEndTime ,带有时间戳。
查找将返回行ID的查询,以获得最小时差。
Select rowId,TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime)) from walks where <time diffence is minimum in the entire database>
另外,如果我想要时间差小于10秒的行。
Select rowId,TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime)) from walks where <time diffence is < 10 seconds>
答案 0 :(得分:0)
非常简单: 具有相应rowId的数据库中的最小值:
Select rowId,MIN(TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime)))
from walks
GROUP BY rowId
ORDER BY MIN(TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime))) ASC
LIMIT 1;
只是值&lt; 10s
Select rowId,TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime))
from walks
where TIME_TO_SEC(TIMEDIFF(cityWalkEndTime,cityWalkStartTime))<10;
答案 1 :(得分:0)
这可以避免两次调用TIMEDIFF。 (它可能不会加速注意事项。)
Select rowId,
TIME_TO_SEC(TIMEDIFF(cityWalkEndTime, cityWalkStartTime)) AS diff
from walks
HAVING diff < 10