我一直在网上学习sql。我对这个问题有些怀疑。这是我的答案,但它没有正常工作。
回答:
select distinct student_name
from student s
join mark m on s.student_id=m.student_id
where value > 50 order by student_name;
您的查询已结束。您只需要检查所有标记是否> 50,而不仅仅是一个。您可以通过student_id分组并使用HAVING
子句断言所有标记> 50,这与最小标记> 50相同:
SELECT s.student_name
FROM student s
JOIN mark m ON s.student_id=m.student_id
GROUP BY s.student_name
HAVING MIN(m.value) > 50
ORDER BY s.student_name
您可以检查所有科目的计数以及学生的科目是否等于50
select m.student_id, count(*) tot_50_count
from mark m
where m.value > 50
gropup by m.student_id
select distinct student_name from student s
join (
select m.student_id, count(*) tot_count
from mark m
group by m.student_id
) t1 on t1.student_id = s.student_id
join (
select m.student_id, count(*) tot_50_count
from mark m
where m.value > 50
group by m.student_id
) t2 on t2.student_id = s.student_id
and t1.tot_count = t2.tot_50_count