java面试题学生表成绩表老师表_[ Java面试题 ]数据库篇

基本表结构:

student(sno,sname,sage,ssex)学生表

course(cno,cname,tno) 课程表

sc(sno,cno,score) 成绩表

teacher(tno,tname) 教师表

1、查询课程1的成绩比课程2的成绩高的所有学生的学号

select a.sno from(select sno,score from sc where cno=1) a,

(select sno,score from sc where cno=2) bwhere a.score>b.score and a.sno=b.sno

2、查询平均成绩大于60分的同学的学号和平均成绩

select a.sno as "学号", avg(a.score) as"平均成绩"from(select sno,score fromsc) agroup by sno having avg(a.score)>60

3、查询所有同学的学号、姓名、选课数、总成绩

select a.sno as 学号, b.sname as姓名,count(a.cno) as 选课数, sum(a.score) as总成绩fromsc a, student bwhere a.sno =b.snogroup by a.sno, b.sname

或者:

selectstudent.sno as 学号, student.sname as姓名,count(sc.cno) as 选课数, sum(score) as总成绩from student left Outer join sc on student.sno =sc.snogroup by student.sno, sname

4、查询姓“张”的老师的个数

selectcount(distinct(tname)) from teacher where tname like ‘张%‘

或者:

select tname as "姓名", count(distinct(tname)) as"人数"fromteacherwhere tname like‘张%‘

group by tname

5、查询没学过“张三”老师课的同学的学号、姓名

select student.sno,student.sname fromstudentwhere sno not in (select distinct(sc.sno) fromsc,course,teacherwhere sc.cno=course.cno and teacher.tno=course.tno and teacher.tname=‘张三‘)

6、查询同时学过课程1和课程2的同学的学号、姓名

select sno, sname fromstudentwhere sno i

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值