首页 > 代码库 > 做项目中遇到所有的常用知识点(javascript、php、mysql、apache、nginx)更新

做项目中遇到所有的常用知识点(javascript、php、mysql、apache、nginx)更新

1.Mysql随机取数据,性能最好的方法:

用join取出一条

SELECT *FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM `table`)) AS id) AS t2WHERE t1.id >= t2.idORDER BY t1.id ASC LIMIT 5;

 取出多条(最大值-最小值)* 随机数 +最小值

SELECT * FROM users WHERE userId >= ((SELECT MAX(userId) FROM users)-(SELECT MIN(userId) FROM users)) * RAND() + (SELECT MIN(userId) FROM users)   LIMIT 1

 

做项目中遇到所有的常用知识点(javascript、php、mysql、apache、nginx)更新