sql 中 sum()和count()计算平均值的问题 drop table #tb1
create table #tb1
(
zhuanye varchar(50),
dengji varchar(50),
psum int,
savg float
)
insert #tb1 (zhuanye,dengji,psum,savg)
select distinct (case when left(banji.bjname,3)='计算机' then '计算机'
else '厨师'
end) zy,
(case when chengji.cj<60 then '不及格'
when chengji.cj<70 and chengji.cj>=60 then '及格'
when chengji.cj<90 and chengji.cj>=70 then '良好'
else '优秀' end) dj, count(bjxs.xsid) rs, [u]sum(chengji.cj)/count(bjxs.xsid) pjf[/u]
from banji
join bjxs on banji.bjid=bjxs.bjid
join xuesheng on xuesheng.xsid=bjxs.xsid
join chengji on chengji.xsid=bjxs.xsid
group by (case when left(banji.bjname,3)='计算机' then '计算机'
else '厨师'
end),(case when chengji.cj<60 then '不及格'
when chengji.cj<70 and chengji.cj>=60 then '及格'
when chengji.cj<90 and chengji.cj>=70 then '良好'
else '优秀' end)