zoukankan      html  css  js  c++  java
  • 50个查询系列-第13个查询:把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;

    UPDATE tblscore SET tblscore.Score=
    
    (
    
    
    -- 这里开始算叶平的平均值
    SELECT AVG(tt.aa) FROM 
    (
    SELECT  tblscore.Score aa FROM tblscore WHERE
    tblscore.CourseId=
    ( 
    
    SELECT tblcourse.CourseId FROM tblcourse WHERE tblcourse.CourseId=(
    SELECT tblteacher.TeaId FROM tblteacher WHERE tblteacher.TeaName='叶平' )
    ))tt -- 算出叶平教得课程的平均值
    
    
     
     
     
     )
     WHERE tblscore.CourseId=
     
     (SELECT tblcourse.CourseId FROM tblcourse WHERE tblcourse.CourseId=(
    SELECT tblteacher.TeaId FROM tblteacher WHERE tblteacher.TeaName='叶平' ))-- 叶平上课的id

    答案的写法:

    Select * Into Sc From tblScore
     go
     Update Sc Set Score=(Select Avg(Score) From tblScore s1 Where s1.CourseId=sc.CourseId) 
      Where CourseId IN
       (Select CourseId From tblCourse cs INNER JOIN tblTeacher tc ON cs.TeaID=tc.TeaID WHERE TeaName ='叶平')
  • 相关阅读:
    Poj3126
    Poj1426
    2806 红与黑
    3100 蜗牛
    1225 八数码难题
    2549 自然数和分解
    2547 东方辉针城
    2928 你缺什么
    1629 01迷宫
    1029 遍历问题
  • 原文地址:https://www.cnblogs.com/shenxiaoquan/p/6135579.html
Copyright © 2011-2022 走看看