摘要:
一直以为mysql随机查询几条数据,就用SELECT*FROM`table`ORDERBYRAND()LIMIT5就可以了。但是真正测试一下才发现这样效率非常低。一个15万余条的库,查询5条数据,居然要8秒以上查看官方手册,也说rand()放在ORDER BY 子句中会被执行多次,自然效率及很低。You cannot use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times.搜索Google,网上基本上都是查询max(id) * 阅读全文