书上给出的DB2,ORACLE,SQLSERVER的解决方案,在SQLSERVER中不能使用。
只能使用中间那个通用的解决办法:
Select e.DEPTNO,sum(e.SAL*(case when eb.TYPE=1 then .1 when eb.TYPE=2 then.2 when eb.TYPE=3 then .3 end)) as total_bonus,total_salfrom EMP e,EMP_BONUS eb, (Select DEPTNO,SUM(sal) as total_sal from EMP where DEPTNO=10 group by DEPTNO) dwhere e.EMPNO = eb.EMPNOand e.DEPTNO = d.DEPTNOgroup by e.DEPTNO,total_sal