mysql 查询多条随机结果
三个字段:id name probability
probability初始默认全是1
probability值越大,随机出来的概率越高。
select * from kzmod_mapchoose order by probability*(SELECT FLOOR( MAX(probability) * RAND()) FROM kzmod_mapchoose ) desc limit 8;
我改了一条数据的值为10,它就一直都出现了。。
怎么改进?还有就是,怎样知道概率值大于平均值多少时,这条数据会百分百出现?
SELECT a.* FROM kzmod_mapchoose a INNER JOIN
(SELECT id,probability*(SELECT FLOOR(MAX(probability) * RAND()) FROM kzmod_mapchoose)
AS aa
FROM kzmod_mapchoose) c
ON a.id=c.id ORDER BY c.aa
select *
from kzmod_mapchoose a, (select sum(probability)*RAND() as k from kzmod_mapchoose) b
where (select sum(probability) from kzmod_mapchoose where probability>=a.probability)> b.k
order by (select sum(probability) from kzmod_mapchoose where probability>=a.probability) desc
limit 1