如何得出每个部门的人数????
select语句得到结果如下:
chr_cl1 chr_cl2
A1供应部 罗杰泷
A1供应部 罗杰泷
A1供应部 罗杰泷
A1供应部 张国
C1系统支持 谢燕山
C1系统支持 谢燕山
上面的结果是A1供应部有两个人,C1系统支持有一个人
但是我想按人名来统计每个部门的人数,希望得到的结果是
chr_cl1 人数
A1供应部 2
C1系统支持 1
试了好几次,都试不出来,哪位兄弟帮帮忙啊?????????????
sql语句如下:
select t.chr_cl1,t.chr_cl2
from zd_report_temp t
where t.program_name in('INVGSTOT')
order by t.chr_cl1
select语句得到结果如下:
chr_cl1 chr_cl2
A1供应部 罗杰泷
A1供应部 罗杰泷
A1供应部 罗杰泷
A1供应部 张国
C1系统支持 谢燕山
C1系统支持 谢燕山
上面的结果是A1供应部有两个人,C1系统支持有一个人
但是我想按人名来统计每个部门的人数,希望得到的结果是
chr_cl1 人数
A1供应部 2
C1系统支持 1
试了好几次,都试不出来,哪位兄弟帮帮忙啊?????????????
sql语句如下:
select t.chr_cl1,t.chr_cl2
from zd_report_temp t
where t.program_name in('INVGSTOT')
order by t.chr_cl1
解决方案 »
- 用java连接数据库,表中有数据,但查询不出来,请教一下
- 各位高手指点下小弟,小弟遇到问题,还请各位帮帮忙select'编号是:'‖empno‖'的雇员,姓名是:'‖ename‖',工作是:'‖job from emp
- orcal 中查询10天数据 存储过程怎么写 在线等待(急)
- sql查询的问题?
- 请教用PL/SQL对表的备份,生成的是表空间,用户,表结构,数据。成sql脚本
- CBO 基于成本的优化器
- oracle:存储过程中能否执行exp/imp 语句??
- 取系统时间问题
- 如何实现这个替换功能?
- trigger:每次update table1,table2字段值自增1,不运行?
- 如何从重复数据中找出日期最后的一条???
- sql 优化
--重復帖?
select chr_cl1,count(distinct(chr_cl2)) 人数
from zd_report_temp
group by chr_cl1;
from zd_report_temp t
where t.program_name in('INVGSTOT')
group by t.chr_cl1
from zd_report_temp t
where t.program_name in('INVGSTOT')
group by t.chr_cl1;
--创建部门表
create table department
(
chr_cl1 varchar2(100),
chr_cl2 varchar2(100)
)
--添加测试数据
insert into department
select 'A1供应部','罗杰泷' from dual union all
select 'A1供应部','罗杰泷' from dual union all
select 'A1供应部','罗杰泷' from dual union all
select 'A1供应部','张国' from dual union all
select 'C1系统支持','谢燕山' from dual union all
select 'C1系统支持','谢燕山' from dual
commit;
--部门人数统计
select chr_cl1 as 部门,count(distinct chr_cl2) as 人数 from department group by chr_cl1--查询结果
A1供应部 2
C1系统支持 1
from test
group by chr_cl1
select t.chr_cl1,count(t.chr_cl2) from
(select distinct chr_cl1,chr_cl2) from zd_report_temp
where program_name in('INVGSTOT')
) t
group by chr_cl1
order by chr_cl1
select t.chr_cl1,count(t.chr_cl2) from
(select distinct chr_cl1,chr_cl2 from zd_report_temp
where program_name in('INVGSTOT')
) t
group by chr_cl1
order by chr_cl1