张生 发表于 2011-2-20 00:10:16

gdtv 发表于 2011-2-20 00:11:35

这样是调用随机的60条

正确的方法我也不懂

大概方法是,按正常顺序调用最后的60条,返回数组,再把这个数组的顺序打乱

[ 本帖最后由 gdtv 于 2011-2-20 00:12 编辑 ]

Kokgog 发表于 2011-2-20 00:22:07

要用子查询

select*from (select * from table_name order by PK desc limit 0,60) tmp_table order by rand()

但是性能不是最好

select * from table_name order by PK desc limit 0,60获取数据,然后用程序shuffle列表相对好一点

xspoco 发表于 2011-2-20 00:31:24

yc014t 不会技术的路过...

zllovesuki 发表于 2011-2-20 03:06:56

select * from news order by rand() desc limit 60

shy9000 发表于 2011-2-20 03:22:13

原帖由 zllovesuki 于 2011-2-20 03:06 发表 http://hostloc.wiki/images/common/back.gif
select * from news order by rand() desc limit 60
嗯,倒序加上了,然后应该limit应该规定开始位置,从第0条记录开始的吧?select * from news order by rand() desc limit 0,60

Captain 发表于 2011-2-20 04:16:28

原来这里还可以问这些问题的
看来下次有地方发问了 :lol

张生 发表于 2011-2-20 20:56:41

Kokgog 发表于 2011-2-20 21:05:18

原帖由 张生 于 2011-2-20 20:56 发表 http://hostloc.wiki/images/common/back.gif


这条代码我用在ECMS上面的,如果按照这种写法,每次生成一个页面要消耗2~5秒

这是全部记录打乱之后取倒序60条,不是倒序取60条然后打乱, mysql全部记录order by rand效率肯定低的,你真的要实现这个,可以搜下order by rand mysql 效率这几个关键词,有人写过存储过程版,子查询版,表连接版的替代优化方式的

googlebot2 发表于 2011-2-21 07:41:32

rand() 非常慢
页: [1] 2
查看完整版本: 调用最后60条记录,然后随机排序