我目前正试图将一系列聚合函数作为百分比返回。有人对如何做有任何建议吗?
以下是SQL。
SELECT
et.Term
,count(et.employeeid) as 'Total Enrolled'
,sum(et.retained) as 'Retained'
,sum(et.EnrollButSwitchedDept) as 'EnrollButSwitched'
,sum(et.NotEnrolled) as 'Not Enrolled'
,sum(et.Graduated) as 'Graduated'
--,CAST(sum(et.retained))*100.0 as 'Retained %'
,CAST (((sum(et.retained))*100.0)/(((count (et.EmployeeID)))) as Numeric(10,2) as 'Retained %'
FROM #EnrollmentTypes et
WHERE 1 = 1
GROUP BY et.Term
截至目前,我收到了以下错误。
Incorrect syntax near 'CAST', expected 'AS'.
答案 0 :(得分:1)
如果你摆脱了一些不必要的括号,那么将更容易看到剩下的应该去哪里。应该有效的更正查询:
Swift.String