你好,有人可以像我在标题中所说的那样帮我查询吗? Atm我没有任何想法如何做到这一点。我想要的是当我按下一个按钮来随机显示用户,但那些投票较少的用户在随机sql中有更多的权重。
这是我的实际sql
$query = "select * from `users` where username!='$user' ".$conditie_categ." order by RAND() limit 1 ";
$result = mysqli_query($dbc,$query)
or die("query failed: " . mysqli_error($dbc));
Thnx提前。
答案 0 :(得分:2)
...粗略地
SELECT * FROM ints;
+---+
| i |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+---+
SELECT i
, RAND()/(i+1) wght
FROM ints
ORDER
BY wght DESC;
+---+-----------------------+
| i | wght |
+---+-----------------------+
| 1 | 0.4722126251759125 |
| 0 | 0.3937836097495478 |
| 3 | 0.217650386474701 |
| 2 | 0.18025848441470893 |
| 4 | 0.14613628009905694 |
| 7 | 0.11937898478412906 |
| 8 | 0.08080622240562157 |
| 9 | 0.07711844041675184 |
| 5 | 0.006933732585609331 |
| 6 | 0.0022811152594387277 |
+---+-----------------------+
较低值趋势显示在列表顶部。