求标准分sql

if object_id('tempdb..#tempTable') is not null Begin
 drop table #tempTable
End

SELECT TOP 1000 [校区],[学年],[考试年级],[考试类别],avg(语文含挑战) '平均分',STDEV(语文含挑战) '标准差'
into #tempTable FROM [SchoolAnalyze].[dbo].[成绩分析]group by  [校区],[学年],[考试年级]      ,[考试类别]

update [SchoolAnalyze].[dbo].[成绩分析]
set [语文含挑战标准分] = ([语文含挑战] - (select 平均分 from #tempTable where 校区 = [成绩分析].校区 and 学年 = [成绩分析].学年 and 考试年级 = [成绩分析].考试年级 and 考试类别 = [成绩分析].考试类别))/
                          (select 标准差 from #tempTable where 校区 = [成绩分析].校区 and 学年 = [成绩分析].学年 and 考试年级 = [成绩分析].考试年级 and 考试类别 = [成绩分析].考试类别)

select * from #tempTable
if object_id('tempdb..#tempTable') is not null Begin
 drop table #tempTable
End

 

posted @ 2017-09-24 16:26  shiningrise  阅读(355)  评论(0编辑  收藏  举报