日期:2014-05-17 浏览次数:20856 次
create table t1 ( id int, name varchar2(20), dno number, ) declare begin for i in 42..51 loop insert into t1 values(i,'test',10007); end loop; end; create table t2 ( id int, name varchar2(20), dno number, type int ) insert into t2 values(1,'销售部',10005,0); insert into t2 values(2,'销售分部',10015,1); insert into t2 values(3,'销售分部',10025,1); insert into t2 values(4,'人事部',10006,0); insert into t2 values(5,'管理办',10007,0); select name,a1.dno,a1.人员总数,a2.合计 from ( select t2.name,t2.dno, count(t2.dno) 人员总数,t2.type from t1,t2 where t1.dno=t2.dno group by t2.name,t2.dno,t2.type) a1, (select t2.type,count(t2.type) 合计 from t1,t2 where t1.dno=t2.dno group by t2.type) a2 where a1.type=a2.type name dno 人员总数 合计 1 销售分部 10025.0 8 35 2 销售分部 10015.0 7 35 3 销售部 10005.0 20 35 4 人事部 10006.0 6 6 5 管理办 10007.0 10 10