日期:2014-05-17 浏览次数:20679 次
with T_COMPANY(emp_id, company_id, department_id, salary) as ( select 1, '公司1', '部门1', 1000 from dual union all select 2, '公司1', '部门2', 1000 from dual union all select 3, '公司1', '部门2', 1000 from dual union all select 4, '公司2', '部门1', 1000 from dual union all select 5, '公司2', '部门1', 1000 from dual union all select 6, '公司2', '部门2', 1000 from dual union all select 7, '公司3', '部门1', 1000 from dual ) select decode(grouping(company_id), 1, '所有公司', company_id), decode(grouping(department_id), 1, '所有部门', department_id), sum(salary), avg(salary) from t_company group by cube(company_id,department_id);