上面有笔误
select * from test as t1 join (select round(rand() * (select max(temID) from `test`)) as temID) as t2
where t1.temID >= t2.temID
order by t1.temID asc limit 3;
781和812还算连续数据嘛?你这成环形链表了。
select * from test as t1 join (select round(rand() * (select max(temID) from `test`)) as id) as t2
where t1. temID >= t2. temID
order by t1. temID asc limit 3;
这个只支持123,234、456这样的,不支持你那种环状的。要做到那种环状的,一条sql搞不定,得写存储过程,判断是否取出了几条结果,如果不足3条,就从开头开始取,补足3条。用php做也是这个思路。