我有一张表,上面有时间戳记。现在我需要获取最早的记录和最新的记录
9/10/2014 6:54
9/10/2014 6:53
9/10/2014 6:51
9/8/2014 8:09
9/8/2014 7:00
9/5/2014 7:38
9/5/2014 3:57
9/5/2014 3:51
9/4/2014 11:09
9/4/2014 8:39
目前,这是我通过发送两个数据库调用来获取它们的方法,这会减慢处理速度
$new_timestamp = mysql_query("SELECT TIMESTAMP FROM $rectable ORDER BY TIMESTAMP DESC LIMIT 1");
$col_old = mysql_fetch_assoc($new_timestamp);
$old = $col_new['TIMESTAMP'];
$new_timestamp1 = mysql_query("SELECT TIMESTAMP FROM $rectable ORDER BY TIMESTAMP ASC LIMIT 1");
$col_new = mysql_fetch_assoc($new_timestamp1);
$new = $col_new['TIMESTAMP'];
有什么方法可以优化此代码和完全填充需求,而无需通过特殊查询或存储过程发送两个数据库调用
您可以使用max
和min
获取最新和最旧的时间戳记
select max(timestamp), min(timestamp) from mytable
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句