MySQL读取随机记录的实现方法有很多,现总结两种: 用法一:适用于小数据量的数据表(Table)
SELECt * from TABLE order by RAND() LIMIT 1
用法二:可用于大数据量的数据表(Table)
SELECt Column FROM table AS r1 JOIN (SELECt MAX(Id) AS wid_c FROM table) AS tmp1 WHERe r1.Id >= (SELECT (RAND() * tmp1.wid_c) AS id) LIMIT 10
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)