当前位置:
  1. 首页 »
  2. 标签:php大数据查询
共 1 篇

大数据SQL随机查询

PHP SQL随机查询数据小的话还是用rand() 比较方面。如果数据太多的话,可以建立临时附表查询。或者用join链接。rand()在大数据上有很大的概率就直接挂掉! $sql1 = “SELECT * FROM `表名` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `表名`)-(SELECT MIN(id) FROM `表名`))+(SELECT MIN(id) FROM `表名`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1”; 添加下具体查询更
教程 2,456