三张表查询出选了两门课以上的学生,学生表课程表选课表sql怎么写
2个回答
推荐于2018-03-28
展开全部
学生表:student(学号:sno、姓名:sname、性别:sgender、年龄:sage)
课程表:couse (课程编号:cno、课程名称:cname)
选课表:sc(学号:sno、课程编号:cno、成绩:marks)
SELECT s.sno ,
s.sname ,
c.cname
FROM student s
INNER JOIN sc t1 ON t1.sno = s.sno
INNER JOIN couse c ON sc.cno = c.cno
WHERE s.sno IN ( SELECT t.sno
FROM sc t
GROUP BY t.sno
HAVING COUNT(t.cno) = 2 )
课程表:couse (课程编号:cno、课程名称:cname)
选课表:sc(学号:sno、课程编号:cno、成绩:marks)
SELECT s.sno ,
s.sname ,
c.cname
FROM student s
INNER JOIN sc t1 ON t1.sno = s.sno
INNER JOIN couse c ON sc.cno = c.cno
WHERE s.sno IN ( SELECT t.sno
FROM sc t
GROUP BY t.sno
HAVING COUNT(t.cno) = 2 )
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询