1./查询年龄小于17岁的女学生的学号和姓名/
select sno,sname from s
where age < 17 and sex="f"
2./检索男学生所学课程的课程号和课程名。/
方法一:
select cno,cname from c
where cno in(
select cno from sc
where sno in(
select sno from s
where sex="m"))
方法二:
select DISTINCT c.cno, c.cname from c,sc,s
where c.cno=sc.cno and s.sno=sc.sno and sex="m"
3./检索男学生所学课程的任课老师的工号和姓名。/
select DISTINCT t.tno,t.tname from t,c,s,sc
where t.tno=c.tno and c.cno=sc.cno and s.sno=sc.sno
4./检索至少选修两门课程的学生学号。/
select sno from sc
group by sno
having count(sno)>=2
5./检索至少有学号为S2和S4学生选修的课程的课程号。/
select DISTINCT cno from sc
where sno="s2" or sno="s4"
6./检索王同学不学的课程的课程号。/
select cno from c
where cno not in(
select cno from sc
where sc.sno in(
select sno from s
where sname = "王"))
7./检索全部学生都选修的课程的课程号与课程名。/
select cno,cname from c
where cno in(
select cno from sc
group by cno
having count(cno)=(
select count(*) from s))
8./检索选修课程包含张xx所授全部课程的学生学号/
select sno from sc
where cno in(
select cno from c
where tno in(
select tno from t
where tname ="张xx"))
标签:语句,sno,课程,sql,sc,cno,where,select
From: https://www.cnblogs.com/ZarkY/p/17226857.html