如何解决有人可以在此dbms查询中为我提供帮助吗?
编写查询以显示在每个学科中获得最高分的学生的姓名,并按学科名称以升序排列。如果有多个顶部,请按字母顺序显示其名称。 将其显示为subject_name和student_name。 O / P:第一列-subject_name 第二列-学生名
我的答案-
select su.subject_name,st.student_name from subject su,student st,mark m
where m.student_id = st.student_id and m.subject_id = su.subject_id
and m.value = (select max(value) from mark group by subject_id);
错误-
and m.value = (select max(value) from mark group by subject_id)
*
ERROR at line 3:
ORA-01427: single-row subquery returns more than one row
我知道的是,我将不得不进行另一个子查询,例如
and m.value =(select..... (select max(value) from mark group by subject_id));
但是我不明白。
解决方法
没关系,我们将不得不使用IN运算符和俱乐部值,subject_id,因为它们是一组。
SELECT su.subject_name,st.student_name
FROM student s
JOIN mark m ON st.student_id = m.student_id
JOIN subject su ON m.subject_id = su.subject_id
WHERE (m.value,su.subject_id) IN (
SELECT max(value),subject_id FROM mark GROUP BY subject_id
)
ORDER BY su.subject_name,st.student_name;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。