我一直在在线学习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;
答案 0 :(得分:1)
您的查询已结束。您只需要检查所有标记均大于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
答案 1 :(得分:0)
您可以检查所有科目和一个学生的科目> 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