sql - Return an aggregate function as a percentage -


i'm trying return series of aggregate functions percentages. have suggestions on how it?

here sql below.

select  et.term ,count(et.employeeid) 'total enrolled' ,sum(et.retained) 'retained' ,sum(et.enrollbutswitcheddept) 'enrollbutswitched' ,sum(et.notenrolled) 'not enrolled' ,sum(et.graduated) 'graduated' --,cast(sum(et.retained))*100.0 'retained %' ,cast (((sum(et.retained))*100.0)/(((count (et.employeeid)))) numeric(10,2) 'retained %'  #enrollmenttypes et  1 = 1  group et.term 

as of right i'm getting error below.

incorrect syntax near 'cast', expected 'as'. 

if rid of few of unnecessary parentheses easier see remaining should go. corrected query should work:

select  et.term ,count(et.employeeid) 'total enrolled' ,sum(et.retained) 'retained' ,sum(et.enrollbutswitcheddept) 'enrollbutswitched' ,sum(et.notenrolled) 'not enrolled' ,sum(et.graduated) 'graduated' ,cast(sum(et.retained) * 100.0 / count(et.employeeid) numeric(10,2)) 'retained %' #enrollmenttypes et 1 = 1 group et.term 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -