有一个这样的表
professionNo (PK) 职称证书号
teacherNo (FK) 教职工号
professionName 职称
gettime 获取时间例如: professionNo (PK) teacherNo (FK) professionName gettime
00000 11110 教授 2008-1-1
00001 11111 教授 2008-1-1
00002 11112 硕士 2008-2-2
00003 11113 助手 2008-3-3我想得到职称为教授的有多少个,职称为硕士的有多少个. 职称为助手的有多少个
professionNo (PK) 职称证书号
teacherNo (FK) 教职工号
professionName 职称
gettime 获取时间例如: professionNo (PK) teacherNo (FK) professionName gettime
00000 11110 教授 2008-1-1
00001 11111 教授 2008-1-1
00002 11112 硕士 2008-2-2
00003 11113 助手 2008-3-3我想得到职称为教授的有多少个,职称为硕士的有多少个. 职称为助手的有多少个
teacherNo,
professionName ,
count(1) as 个数
from T
group by
teacherNo,
professionName
insert into tb select '00000','11110','教授','2008-1-1'
insert into tb select '00001','11111','教授','2008-1-1'
insert into tb select '00002','11112','硕士','2008-2-2'
insert into tb select '00003','11113','助手','2008-3-3'select professionName,count(1) as '人数'
from tb
group by professionName
professionName 人数
教授 2
硕士 1
助手 1
teacherNo,
professionName ,
count(1) as 个数
from T
group by
teacherNo,
professionName
insert into tb select '00000','11110','教授','2008-1-1'
insert into tb select '00001','11111','教授','2008-1-1'
insert into tb select '00002','11112','硕士','2008-2-2'
insert into tb select '00003','11113','助手','2008-3-3'
goselect professionName , count(*) 人数 from tb group by professionName
/*
professionName 人数
-------------- -----------
教授 2
硕士 1
助手 1(所影响的行数为 3 行)
*/select
教授 = (select count(*) from tb where professionName = '教授'),
硕士 = (select count(*) from tb where professionName = '硕士'),
助手 = (select count(*) from tb where professionName = '助手')
/*
教授 硕士 助手
----------- ----------- -----------
2 1 1(所影响的行数为 1 行)
*/drop table tb
insert into tb select '00000','11110','教授','2008-1-1'
insert into tb select '00001','11111','教授','2008-1-1'
insert into tb select '00002','11112','硕士','2008-2-2'
insert into tb select '00003','11113','助手','2008-3-3'
goselect professionName , count(*) 人数 from tb group by professionName
教授 = (select count(*) from tb where professionName = '教授'),
硕士 = (select count(*) from tb where professionName = '硕士'),
助手 = (select count(*) from tb where professionName = '助手')
//学习,,