统计sql数据库中发信息量最多的用户

来源:百度知道 编辑:UC知道 时间:2024/06/16 02:27:09
一个用户名可以发很多信息,请问如何统计出前五名发信息量最多的用户。

select top 5 用户ID,count(*) ACount from 表 group by 用户ID order by ACount

select top 5 * from (
select userName,count(*) as num from table
where 时间 between '2009-5-1' and '2009-6-1'
group by userName
) as t
order by num desc
我想你应该有时间限制吧.查询该时间段用户所发的信息多少.

根据用户分组,然后对信息数量进行求和,通过order by排序来取出前五名

同意一楼的,
但是做了一点改动
select top 5 * from (select username,count(*) times from table group by username ) as t order by t.times desc

select top 5 * from (select username,count(*) times from table group by username ) as t order by times desc