21,887
社区成员
发帖
与我相关
我的任务
分享
SELECT *, rand() as ord
from tablename
where
rand() <
CASE weight
WHEN 5 THEN 0.3
WHEN 4 THEN 0.55
WHEN 3 THEN 0.75
WHEN 2 THEN 0.9
WHEN 1 THEN 1
END
order by ord
limit 8
create table lk11(
id int not null auto_increment primary key,
weight int
);
insert into lk11(weight) values
(1),(2),(5),(3),(2),(3),(4),(4),(5),(3),(1),(3),(2),(4),(5);
create index `k_w` on lk11(weight);
select * from lk11 order by weight - rand()*5 desc limit 8;
select * from table1 order by rand()*weight desc limit 8;
select * from table order by weight-rand()*5 limit 8
select * from table1 order by floor(1+rand()*5) limit 8;
mysql>select * from table order by floor(weight-1+rand()*2) desc limit 8;