mysql取一段日期内随即 N条记录 比如表A 时间字段为SJ

2025-01-24 05:29:58
推荐回答(2个)
回答1:

假设随机取一天内的五条数据吧
for(i=1;i<=5;i++)
{
$num = mt_random(1,1000);

sql = "select * from table where id = { $num} and sj =时间 ";

}
循环五次。每次取一条、然后自己在存入数组就可以了

回答2:

select * from a where a between '2012-08-25 08:00:00' and '2012-08-25 09:00:00' order by random limit N;