表数据如图所示:
需找出只考了 英语 和数学 并且平均分大于60分的学生,sql如下
SELECT students,AVG(score) FROM demo WHERE students in( SELECT students FROM demo WHERE subjects in('sx','yy') GROUP BY students HAVING COUNT(students)=2 ) GROUP BY students HAVING COUNT(students)=2 AND AVG(score)>60;