有一张表,结构如下:      oragname           rower1.   club1               allen
2.   club1               billy
3.   club2               cindy
4.   club3               dicky

.
.   现在要统计每一个俱乐部里的人数,如:club1      8
club2      3clubN      N    应该用什么语句呢?请各位大大们解答...

解决方案 »

  1.   

    Select oragname,Count(oragname) "people" From CulbTable Group By oragname
      

  2.   

    select oragname , count(*) 人数 from tb group by oragname
      

  3.   

    --注:以下为在sql server中实现的代码.在oracle中,varchar改为varchar2
    create table tb(oragname varchar(10) , rower varchar(10))
    insert into tb values('club1' , 'allen') 
    insert into tb values('club1' , 'billy') 
    insert into tb values('club2' , 'cindy') 
    insert into tb values('club3' , 'dicky')select oragname , count(*) 人数 from tb group by oragnamedrop table tb/*
    oragname   人数          
    ---------- ----------- 
    club1      2
    club2      1
    club3      1(所影响的行数为 3 行)
    */
      

  4.   

    Select oragname,Count(1)  From CulbTable Group By oragname
      

  5.   

    select oragname , count(rower)
    from table
    group by oragname
      

  6.   


    select oragname , count(*) 人数 from tb group by oragname
      

  7.   


    QL> create table tb(oragname varchar(10) , rower varchar(10));表被创建SQL> insert into tb values('club1' , 'allen');1 行 已插入SQL> insert into tb values('club1' , 'allen');1 行 已插入SQL> insert into tb values('club1' , 'billy');1 行 已插入SQL> insert into tb values('club2' , 'cindy');1 行 已插入SQL> insert into tb values('club3' , 'dicky');1 行 已插入SQL> select * from tb;ORAGNAME   ROWER
    ---------- ----------
    club1      allen
    club1      allen
    club1      billy
    club2      cindy
    club3      dickySQL> select oragname , count(*) 人数 from tb group by oragname;ORAGNAME         人数
    ---------- ----------
    club1               3
    club2               1
    club3               1SQL> select oragname , count(distinct rower) 人数 from tb group by oragname;ORAGNAME         人数
    ---------- ----------
    club1               2
    club2               1
    club3               1SQL> rollback;回滚完成
      

  8.   

    其实理解了group by就可以了
      

  9.   


    SELECT oragname,COUNT(oragname) FROM ct GROUP BY oragname