A C
SQL> SELECT e.*, d.dname 2 FROM (SELECT e.deptno, SUM(e.sal) AS s_sal, SUM(e.sal * eb.st) AS s_bonus 3 FROM emp e 4 INNER JOIN (SELECT empno, SUM(TYPE / 10) AS st 5 FROM emp_bonus 6 GROUP BY empno) eb 7 ON e.empno = eb.empno 8 GROUP BY e.deptno) e 9 INNER JOIN dept d 10 ON d.deptno = e.deptno; DEPTNO S_SAL S_BONUS DNAME ---------- ---------- ---------- -------------- 10 8750 2135 ACCOUNTING 1 row selected
SQL> SELECT e.deptno,eb.empno, e.sal, eb.st AS s_bonus 2 FROM emp e 3 INNER JOIN (SELECT empno, SUM(TYPE / 10) AS st 4 FROM emp_bonus 5 GROUP BY empno) eb 6 ON e.empno = eb.empno; DEPTNO EMPNO SAL S_BONUS ---------- ------ ---------- ---------- 10 7782 2450 0.1 10 7839 5000 0.3 10 7934 1300 0.3 3 rows selected
SQL> SELECT e.deptno, eb.empno, e.sal, eb.st AS s_bonus 2 FROM emp e 3 INNER JOIN (SELECT empno, SUM(TYPE / 10) AS st 4 FROM emp_bonus 5 GROUP BY empno 6 HAVING COUNT(*) > 1) eb 7 ON e.empno = eb.empno; DEPTNO EMPNO SAL S_BONUS ---------- ------ ---------- ---------- 10 7934 1300 0.3 1 row selected