21,887
社区成员
发帖
与我相关
我的任务
分享
select t1.t as d1, t2.t as d2, t3.t as d3 from hello as t1
left join hello as t2 on timestampdiff(HOUR, t2.t, t1.t) = 1
left join hello as t3 on timestampdiff(HOUR, t3.t, t2.t) = 1
where t2.t is not null and t3.t is not null
order by rand() limit 1
然后你可以通过for N来动态生成SQL语句。这种方式效率很差,而且也不是最好的方案。
MYSQL版有很多大牛可以解决你的困惑