初学 这个该怎么实现

kfq620821 2011-05-06 07:14:44
现在要编写一个存储过程 现在有表A结构如下
id(部门编号) eid(员工编号) xb(性别)
执行存储过程后在表B 结构如下
id(部门编号) sum(部门人数) fm(男性人数) mm(女性人数) 存储过程主要实现根据输入的部门编号分类统计部门人数、部门男性人数、部门女性人数以及公司所有总人数

请各位高手支个招 不胜感谢
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kfq620821 2011-05-09
  • 打赏
  • 举报
回复
谢谢各位 不胜感激
ssqtjffcu 2011-05-07
  • 打赏
  • 举报
回复

with t as(
select 10 deptid,'1' empid,0 sex from dual
union all
select 10,'2',1 from dual
union all
select 20,'3',0 from dual
union all
select 10,'4',0 from dual
union all
select 30,'5',1 from dual
union all
select 10,'6',0 from dual
union all
select 40,'7',1 from dual
union all
select 40,'8',1 from dual
union all
select 30,'9',0 from dual
)
select deptid "部门",
count(1) 部门人数,
sum(decode(sex, 0, 1, 0)) "部门男性人数",
sum(decode(sex, 0, 0, 1)) "部门女性人数",
sum(count(1)) over() "总数"
from t
group by deptid



部门 部门人数 部门男性人数 部门女性人数 总数
---------- ---------- ------------ ------------ ----------
10 4 3 1 9
20 1 1 0 9
30 2 1 1 9
40 2 0 2 9
304的的哥 2011-05-07
  • 打赏
  • 举报
回复

create table b(
id varchar2(10) references a(id),--与a表id号类型相同
sums number(10),
fm number(10),
mm number(10)
)
/
create or replace procedure pro_show_emp(
id_in in a.id%type
)
as
begin
insert into b
select id,
count(*),
sum(decode(xb,'男',1,0)),
sum(decode(xb,'女',1,0))
from a
where id=id_in;
commit;

exception
when others then
rollback;
end pro_show_emp;
tangren 2011-05-06
  • 打赏
  • 举报
回复
--写个语句,存储过程还是自己动动手吧
SELECT id,
COUNT(*) 部门人数,
SUM(decode(xb, '男', 1, 0)) 男性人数,
SUM(decode(xb, '女', 1, 0)) 女性人数,
FROM a
WHERE id = 指定部门编号

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧