我的表格中有一个名为出价的列,我想列出每个出价值的记录数。
制作TOP TEN列表。
示例:
值为1的出价有5个条目/行。 值为2的出价有3个条目/行。 值为3的出价有8个条目/行。 等
如何制作一个查询,对每个出价进行计数和总结,并按DESCending顺序排序?
感谢任何帮助!
答案 0 :(得分:6)
这应该适用于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
答案 1 :(得分:0)
这个怎么样?
SELECT bid, count(*) as TotalHits
FROM tableName
GROUP BY bid
如果你想按照点击排序的结果,请使用
SELECT bid, count(*) as TotalHits
FROM tableName
GROUP BY bid
ORDER BY TotalHits DESC