MySQL查询实例

数据库内容:

查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

select avg(Degree) from Score where Cno in (select Cno from Score group by Cno having count(*)>5) and Cno like '3%' group by Cno

select avg(Degree) from Score where Cno like '3%' group by Cno having count(*)>5

查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。

select * from Score where Cno ='3-105' and Degree>(select Degree from Score where Sno = '109' and Cno = '3-105')

查询成绩高于学号为109”、课程号为“3-105”的成绩的所有记录。

select * from Score where Degree >(select Degree from Score where Sno = '109' and Cno = '3-105')

查询score中选学多门课程的同学中分数为非最高分成绩的记录。

理解1
select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score b where b.Cno =
a.Cno) 理解2 select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score a where Sno in
(select Sno from Score group by Sno having count(*)>1 ))

查询所有“女”教师和“女”同学的name、sex和birthday.

select Sname,Ssex,Sbirthday from Student where Ssex='女' union
select Tname,Tsex,Tbirthday from Teacher where Tsex='女'

查询Student表中最大和最小的Sbirthday日期值。

select max(Sbirthday) from Student union select min(Sbirthday) from Student

查询Student表中不姓“王”的同学记录。

select * from Student where Sno not in(select Sno from Student where Sname like '王%')

查询和“李军”同性别并同班的同学Sname.

select Sname from Student where Ssex = (select Ssex from Student where Sname='李军') and Class=(select Class from Student where Sname = '李军')

  

转载于:https://www.cnblogs.com/UC0079/p/5979908.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值