我有一个表,其中有一列名为 bid,我想列出每个 bid 值存在多少条记录。
有点像制作前十名列表。
例子:
值为 1 的bid 有 5 个条目/行。 值为 2 的 bid 有 3 个条目/行。 值为 3 的 bid 有 8 个条目/行。 等等
我如何进行查询以对每个出价 进行计数和求和,并按降序对它们进行排序?
感谢任何形式的帮助!
最佳答案
这应该适用于 MySQL
select u.firstname, t.bid, count(*) as counts
from your_table t
join users u on u.bid = t.bid
where t.confirmed <> '0000-00-00 00:00:00'
group by t.bid
order by counts desc
一般情况下是可以的
select u.firstname, t.bid, t.counts
from
(
select bid, count(*) as counts
from your_table
where confirmed <> '0000-00-00 00:00:00'
group by bid
) t
join users u on u.bid = t.bid
order by t.counts desc
关于php - 如何统计谁在MySQL中点击次数最多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18162777/