select year(date) as y,month(date) as m,day(date) as d,count(case when type = 'A' then id end) as a
,count(case when type = 'B' then id end) as b,sum(score) as sc
,sum(amount) as am,(cast(sum(score) as money)/cast(sum(amount) as money)) *100 as result
from tablename where dept_code = '501'
and dept_name = 'it' and year(date) = 2011 and month(date) = 4
group by year(date),month(date),day(date),type