这是oracle中默认用户scott下的表。
本问题涉及到三张表,数据分别如下:
emp表:
dept表:
salgrade表:
按题目要求,sql语句如下:
select b.dname 部门名称,b.counts 部门员工数,b.avgsal 部门平均工资,b.minsal 部门最低工资,a.ename 姓名,c.grade 工资等级
from emp a,
(select b.deptno,b.dname,count(*) counts,round(avg(sal),2) avgsal,min(sal) minsal
from emp a,dept b,salgrade c
where a.deptno=b.deptno and a.deptno=b.deptno
and a.sal between c.losal and hisal
group by b.deptno,b.dname) b,
salgrade c
where a.sal=b.minsal
and a.sal between c.losal and c.hisal
结果如图:
SELECT A.DEPTNO,部门人数,部门平均工资,ENAME,COMM
FROM (
SELECT E.DEPTNO,COUNT(*) "部门人数",AVG(SAL) "部门平均工资"
FROM EMP E
GROUP BY E.DEPTNO) A,
(SELECT DEPTNO,E.ENAME,COMM
FROM EMP E
WHERE (DEPTNO,SAL) IN (SELECT E.DEPTNO,MIN(SAL)
FROM EMP E
GROUP BY E.DEPTNO)) B
WHERE A.DEPTNO=B.DEPTNO
一张表??? 给出表结构晒..