Reporting Function

SELECT ID,DepartmentID,Pay,
SUM(PAY) Over(Partition BY DepartmentID)as Total,
Pay*100/SUM(Pay) Over(Partition by DepartmentID) as "Pct of c2"
FROM TempTable
WHERE DepartmentID IN(15,20);

SUM(PAY) Over(Partition BY DepartmentID)as Total
这句话是求出这个用户所有部门得工资总合。
Pay*100/SUM(Pay) Over(Partition by DepartmentID) as "Pct of c2"
这句话是求出这个用户所发得工资所在这个部门工资总合得百分比是多少。
"Pct of c2"
这个是如果取得别名中间有空格,那么就得用双引号引起来。 

posted on 2007-04-02 00:01  小土泥  阅读(206)  评论(0编辑  收藏  举报

导航