查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩

建表语句点击详见

– 查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩


SELECT 

st.s_id,
st.s_name,
sc.c_id,
sc.s_score
 
FROM student st 
LEFT JOIN score sc ON sc.s_id=st.s_id
LEFT JOIN course c ON c.c_id=sc.c_id
WHERE (
SELECT 

COUNT(1)
 
FROM student st2 
LEFT JOIN score sc2 ON sc2.s_id=st2.s_id
LEFT JOIN course c2 ON c2.c_id=sc2.c_id
WHERE sc.s_score=sc2.s_score AND c.c_id!=c2.c_id 
)>1

你可能感兴趣的:(数据库)