当前位置: 代码迷 >> Sql Server >> 求優化,该如何解决
  详细解决方案

求優化,该如何解决

热度:372   发布时间:2016-04-27 11:13:11.0
求優化
SQL code
select name from STUDENT where id in (select studentid from EXAM where score in(SELECT score FROM EXAM WHERE lessonid='10004' group by score having score <=(select avg(score) from EXAM where Lessonid ='10004') )and lessonid ='10004')

這個查詢語句有沒有簡單一點的寫法呢
或者用存儲過程?

------解决方案--------------------
你的语句怎么要4层查询啊?太复杂了吧?不就是找出10004这门课低于平均分的学生吗?试试下面的,没数据不要测
SQL code
SELECT  nameFROM    STUDENTWHERE   id IN ( SELECT  studentid                FROM    EXAM                WHERE   lessonid = '10004'                        AND score <= ( SELECT   AVG(score)                                       FROM     EXAM                                       WHERE    Lessonid = '10004'                                     ) )
  相关解决方案