select max(datatime) as id from mytable   ---全表检索,时间慢
执行时间5分钟

select max(datatime) as id from mytable where citycode=113   --利用索引查询113的记录,然后获取最新时间
执行时间1秒

SELECT datatime from mytable WHERE citycode=113 ORDER BY id DESC LIMIT 1     --利用索引查询113的记录,然后获取最新时间
执行时间1秒

 
 

相关文章: