2

2つのテーブルがあります。1つは学生namesとを含みsids、もう1つはとを含む「テイク」テーブルです。sids of studentsgrades

学生名「Peter-Parker」よりも平均が大きい学生の名前を表示したいと思います。

以下のクエリを試しましたが、機能しません。

SELECT s.sid, s.fname, s.lname
FROM student s, take t
WHERE s.sid = t.sid AND AVG(t.grade) > ALL(
SELECT AVG(grade)
FROM take, student
WHERE student.fname = 'Ali' and student.lname='Demir');
 WITH AliAv(avg) AS
 (SELECT AVG(grade) from take t, student s
 where t.sid = s.sid ands.fname = 'Ali' and s.lname = 'Demir')
 select student.sid, student.fname, student.lname
 from student, take
 where student.sid = take.sid Group by student.sid
 having avg(take.grade) > AliAv.av;
4

2 に答える 2

2
SELECT s.sid, s.fname, s.lname, AVG(t.grade) AS average
FROM student AS s
JOIN take AS t ON t.sid = s.sid
GROUP BY s.sid
HAVING average > (
    SELECT AVG(t2.grade)
    FROM student AS s2
    JOIN take AS t2 ON t2.sid = s2.sid
    WHERE s2.fname = 'Peter' and s2.lname = 'Parker'
)
于 2012-12-29T13:30:37.217 に答える
0

これは SQL Server で機能しますが、構文が MySQL で有効かどうかはわかりません。

SELECT *
FROM Student s
WHERE
  (SELECT AVG(Grade) FROM Take WHERE SID=s.ID) > (SELECT AVG(Grade) FROM Take WHERE SID = (SELECT SID FROM Student WHERE FName='Peter' AND LName='Parker'))
于 2012-12-29T13:42:02.110 に答える