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"
这个是如果取得别名中间有空格,那么就得用双引号引起来。