我对嵌套SELECT有问题 我收到以下错误消息:“选择对于此服务器版本在此位置无效,期望使用'('与”
SELECT group_id, count (student_id)
FROM
(
SELECT student.group_id, student.student_id, AVG(mark)
FROM
student, group, result
WHERE
student.student_id = result.student_id
and
student.group_id = group.group_id
GROUP BY student.group_id, student.student_id
) AS ”p”
p.AVG > 4
GROUP BY group_id
ORDER BY count (student_id) DESC
LIMIT 1;
,我不知道如何解决。请帮帮我!
预先感谢您的回答
答案 0 :(得分:0)
我将从修复两件事开始:
group
是保留字。如果将它用作表名(尽量不要使用),则需要将其引用。AVG(mark)
命名为avg_mark
。WHERE
子句。尝试以下查询:
SELECT group_id, count (student_id)
FROM
(
SELECT student.group_id, student.student_id, AVG(mark) as avg_mark
FROM
student, `group`, result
WHERE
student.student_id = result.student_id
and
student.group_id = `group`.group_id
GROUP BY student.group_id, student.student_id
) p
WHERE avg_mark > 4
GROUP BY group_id
ORDER BY count (student_id) DESC
LIMIT 1;