with emp as(
select '张丰' 教师,'教授' 职称,55 年龄 from dual union all
select '王郅' 教师,'副教授' 职称,44 年龄 from dual union all
select '李娜' 教师,'讲师'职称,42 年龄 from dual union all
select '张贴' 教师,'助教' 职称,38 年龄 from dual union all
select '李自成' 教师,'讲师' 职称,33 年龄 from dual union allselect '吴宇川' 教师,'教授' 职称,55 年龄 from dual union all
select '高希希' 教师,'副教授' 职称,34 年龄 from dual union all
select '邓菲' 教师,'讲师' 职称,42 年龄 from dual union all
select '方舟子' 教师,'助教' 职称,38 年龄 from dual union all
select '王一定' 教师,'讲师' 职称,33 年龄 from dual )要如下统计结果
不知道怎么处理 help~~ 51-60 41-50 31-40 21-30
教授
副教授
讲师
助教
小计
select '张丰' 教师,'教授' 职称,55 年龄 from dual union all
select '王郅' 教师,'副教授' 职称,44 年龄 from dual union all
select '李娜' 教师,'讲师'职称,42 年龄 from dual union all
select '张贴' 教师,'助教' 职称,38 年龄 from dual union all
select '李自成' 教师,'讲师' 职称,33 年龄 from dual union allselect '吴宇川' 教师,'教授' 职称,55 年龄 from dual union all
select '高希希' 教师,'副教授' 职称,34 年龄 from dual union all
select '邓菲' 教师,'讲师' 职称,42 年龄 from dual union all
select '方舟子' 教师,'助教' 职称,38 年龄 from dual union all
select '王一定' 教师,'讲师' 职称,33 年龄 from dual )要如下统计结果
不知道怎么处理 help~~ 51-60 41-50 31-40 21-30
教授
副教授
讲师
助教
小计
解决方案 »
- oracle 11g em重建,提示口令无效。口令用pl/SQL都能登录,就EMCA说无效!
- 未能加载文件或程序集“System.Data.OracleClient”,求助
- 关于一个oracle怪异问题(minus),谁来帮忙解释一下啊
- 求oracle数据库中的一个查询语句。??十分感谢。
- 关于Oracle关联算法的优化
- 我在使用exp,imp时遇到的问题,请高手帮我解决一下。
- 请教:用户及密码放在哪个文件下
- 客户端问题
- VB连接Oracle出错:Run-time-error'...为什么?
- 临时表,rowtype ,record ,table 性能比较
- 关于oracle的更新效率问题,select时很快,但update就很慢
- sqlplus报错信息乱码问题
sum(case when 年龄 between 51 and 60 then 1 else 0 end) '51-60',
sum(case when 年龄 between 41 and 50 then 1 else 0 end) '41-50',
sum(case when 年龄 between 31 and 40 then 1 else 0 end) '31-40',
sum(case when 年龄 between 21 and 20 then 1 else 0 end) '21-30'
from emp
group by 教师
union all
select '小计' 教师 ,
sum(case when 年龄 between 51 and 60 then 1 else 0 end) '51-60',
sum(case when 年龄 between 41 and 50 then 1 else 0 end) '41-50',
sum(case when 年龄 between 31 and 40 then 1 else 0 end) '31-40',
sum(case when 年龄 between 21 and 20 then 1 else 0 end) '21-30'
from emp
,count(case when 年龄 between 51 and 60 then 教师 end) "51-60"
,count(case when 年龄 between 41 and 50 then 教师 end) "41-50"
,count(case when 年龄 between 31 and 40 then 教师 end) "31-40"
,count(case when 年龄 between 21 and 30 then 教师 end) "21-30"
from tmp
group by 职称;
加个cubeselect 职称
,count(case when 年龄 between 51 and 60 then 教师 end) "51-60"
,count(case when 年龄 between 41 and 50 then 教师 end) "41-50"
,count(case when 年龄 between 31 and 40 then 教师 end) "31-40"
,count(case when 年龄 between 21 and 30 then 教师 end) "21-30"
from tmp
group by cube(职称);
2 select '张丰' 教师,'教授' 职称,55 年龄 from dual union all
3 select '王郅' 教师,'副教授' 职称,44 年龄 from dual union all
4 select '李娜' 教师,'讲师'职称,42 年龄 from dual union all
5 select '张贴' 教师,'助教' 职称,38 年龄 from dual union all
6 select '李自成' 教师,'讲师' 职称,33 年龄 from dual union all
7 select '吴宇川' 教师,'教授' 职称,55 年龄 from dual union all
8 select '高希希' 教师,'副教授' 职称,34 年龄 from dual union all
9 select '邓菲' 教师,'讲师' 职称,42 年龄 from dual union all
10 select '方舟子' 教师,'助教' 职称,38 年龄 from dual union all
11 select '王一定' 教师,'讲师' 职称,33 年龄 from dual )
12 select decode(grouping(职称),1,'小计',职称) "职称",
13 count(case when 年龄 between 51 and 60 then 教师 end) "51-60",
14 count(case when 年龄 between 41 and 50 then 教师 end) "41-50",
15 count(case when 年龄 between 31 and 40 then 教师 end) "31-40",
16 count(case when 年龄 between 21 and 30 then 教师 end) "21-30"
17 from emp
18* group by rollup(职称)
SQL> /职称 51-60 41-50 31-40 21-30
------ ---------- ---------- ---------- ----------
副教授 0 1 1 0
讲师 0 2 2 0
教授 2 0 0 0
助教 0 0 2 0
小计 2 3 5 0