觉得你的需求不清楚,
department 什么字段? WEB方式 移动方式
部门名称1 统计值? 移动用户?
部门名称2 统计值? 非...? ?...
部门名称3 统计值? 统计值?
... 统计值? 统计值?
部门名称n 统计值? 统计值?其中多处的“统计值”究竟想要取得什么值?
department 什么字段? WEB方式 移动方式
部门名称1 统计值? 移动用户?
部门名称2 统计值? 非...? ?...
部门名称3 统计值? 统计值?
... 统计值? 统计值?
部门名称n 统计值? 统计值?其中多处的“统计值”究竟想要取得什么值?
select c.department,count(a.userid),sum(decode(a.username,'移动用户',1,0)),sum(decode(a.username,'web用户',1,0))
from op_log a,op_access b,dept_c c
where a.userid=b.userid and b.department=c.dept_no
group by c.department;
from op_log a,op_access b,dept_c c
where a.userid=b.userid and b.department=c.dep_no
group by c.department;
---------- ----------
200306 移动用户
200307 移动用户
200308 移动用户
200309 非移动用户
200310 非移动用户
200311 非移动用户
200301 移动用户
200302 移动用户
200303 非移动用户
200304 非移动用户
200305 移动用户11 rows selectedSQL> select * from op_access;USERID DEPARTMENT
---------- ----------
200304 财务部
200305 行政部
200306 行政部
200307 行政部
200307 技术部
200308 技术部
200309 技术部
200309 生产部
200310 生产部
200301 技术部
200302 销售部
200303 技术部12 rows selected下面是统计语句:
SQL> select ddd.department 部门名称,count(ddd.department) 数量,
2 d.username Web方式,count(username) 移动方式
3 from op_log d,op_access dd,dept_c Ddd
4 where d.userid=dd.userid
5 group by ddd.department,username
6 ;部门名称 数量 WEB方式 移动方式
---------- ---------- ---------- ----------
财务部 7 移动用户 7
财务部 5 非移动用户 5
技术部 7 移动用户 7
技术部 5 非移动用户 5
生产部 7 移动用户 7
生产部 5 非移动用户 5
销售部 7 移动用户 7
销售部 5 非移动用户 5
行政部 7 移动用户 7
行政部 5 非移动用户 510 rows selected
SQL> select * from op_log;USERID USERNAME
---------- ----------
200306 移动用户
200307 移动用户
200308 移动用户
200309 非移动用户
200310 非移动用户
200311 非移动用户
200312 移动用户
200313 移动用户
200314 移动用户
200301 移动用户
200302 移动用户
200303 非移动用户
200304 非移动用户
200305 移动用户14 rows selectedSQL> select * from op_access;USERID DEPARTMENT
---------- ----------
200304 财务部
200305 行政部
200306 行政部
200307 行政部
200308 技术部
200309 生产部
200310 生产部
200311 财务部
200312 财务部
200313 财务部
200314 生产部
200301 技术部
200302 销售部
200303 技术部14 rows selected统计语句:
SQL> select ddd.department 部门名称,count(ddd.department) 数量,
2 d.username Web方式,count(username) 移动方式
3 from op_log d,op_access dd,dept_c Ddd
4 where d.userid=dd.userid and dd.department=ddd.department
5 group by ddd.department,d.username
6 ;部门名称 数量 WEB方式 移动方式
---------- ---------- ---------- ----------
财务部 2 移动用户 2
财务部 2 非移动用户 2
技术部 2 移动用户 2
技术部 1 非移动用户 1
生产部 1 移动用户 1
生产部 2 非移动用户 2
销售部 1 移动用户 1
行政部 3 移动用户 38 rows selected