有一张表,结构如下: oragname rower1. club1 allen
2. club1 billy
3. club2 cindy
4. club3 dicky
.
.
. 现在要统计每一个俱乐部里的人数,如:club1 8
club2 3clubN N 应该用什么语句呢?请各位大大们解答...
2. club1 billy
3. club2 cindy
4. club3 dicky
.
.
. 现在要统计每一个俱乐部里的人数,如:club1 8
club2 3clubN N 应该用什么语句呢?请各位大大们解答...
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 行)
*/
from table
group by oragname
select oragname , count(*) 人数 from tb group by oragname
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;回滚完成
SELECT oragname,COUNT(oragname) FROM ct GROUP BY oragname