sql统计相同项个数并按名次显示

现在有如下这样一个表:
A表
ID Name time
------------------------------
0001 aaa 2006-11-18
0002 ccc 2006-11-18
0003 eee 2006-11-18
0004 aaa 2006-11-18
0005 eee 2006-11-18
0004 aaa 2006-11-18
0002 ccc 2006-11-19

我现想实现的统计结果如下表
按日期当天(2006-11-18)统计后为:
Name 次数 排名(按出现的次数)
-------------------------------------------
aaa 3 1
ccc 1 3
eee 2 2

oracle sql语句如下:

Java代码  收藏代码
select aa.*, rownum as mc from  

select name,count(id) as cnt from ncsuser.sql_example 
where time=to_date('2006-11-18','YYYY-MM-DD') 
group by name 
order by cnt desc 
) aa 
order by name; 

猜你喜欢

转载自279234058.iteye.com/blog/2226895
今日推荐