数据库原理8个例子sql语句

习题

select s#,score from sc where c#=2

select s.s#,s.sname from s,sc where s.s#=sc.s# and c#=2

select distinct s.s#,s.sname from s,sc,c,t
where s.s#=sc.s# and sc.c#=c.c# and c.t#=t.t# and t.tname='john'

select distinct t.s# from sc t where t.c#=1 or t.c#=2;

select t.s# from sc t,sc s where t.s#=s.s# and t.c#=1 and s.c#=2

--查询不学2号课程的所有学生

select distinct s.s# from sc s where s.s# not in(select distinct t.s# from sc t where t.c#=2);

--检索查询学过所有课程的学生

select distinct(sc.s#),s.sname from sc,s where sc.s#=s.s# group by sc.s#,s.sname having count(sc.c#)=all(select count(t.c#) from c t)

--检索所学课程包含学号为s3 所学课程的学生号
select s.s# from sc s where exists
 (select a.c# from sc a where a.s#=3 and a.c#=s.c#) group by s.s# having count(s.c#)=all(
select count(a.c#) from sc a where a.s#=3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值