gpt4 book ai didi

mysql - 使用与前 10 名不同的内容

转载 作者:行者123 更新时间:2023-11-29 23:53:11 25 4
gpt4 key购买 nike

我想从名为 log_buyers 的数据库中选择用户。 log_buyers 是我向用户出售的所有商品的日志。我在字段 USERID 上使用 DISTINCT 仅收集一次买家(有些人购买更多商品)。我这样使用它:

$lsel_log = mysql_query("select DISTINCT userid from log_buyers order by id");
while ($log = mysql_fetch_array($lsel_log)) {

现在我想要 10 个最常见的用户,并查看排名靠前的每个用户的付费金额。在同一个表(log_buyers)中。

  $lsel_log = mysql_query("select DISTINCT userid from log_buyers order by id");
while ($log = mysql_fetch_array($lsel_log)) {

$lsel_total_5 = mysql_query("select * from log_buyers where userid = '$log[userid]' order by id desc");
$total = mysql_num_rows($lsel_total_5);
$total = $total * 5;
echo "$log[userid] - $total";

该代码运行良好,但他是为所有购买的用户执行此操作。我只想为前 10 位用户执行此操作。 (最常见于 log_buyers)。

最佳答案

Using GROUP BY with COUNT应该会为您提供该表中最常见的userid

SELECT userid FROM log_buyers 
GROUP BY userid
ORDER BY COUNT(userid) DESC
LIMIT 10

关于mysql - 使用与前 10 名不同的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25509573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com