SQL COOKBOOK 练习3.9在SQL SERVER下的错误
书上给出的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_salfrom EMPwhere DEPTNO=10group by DEPTNO) dwhere e.EMPNO = eb.EMPNOand e.DEPTNO = d.DEPTNOgroup by e.DEPTNO,total_sal