博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL查询实例
阅读量:5328 次
发布时间:2019-06-14

本文共 1531 字,大约阅读时间需要 5 分钟。

数据库内容:

查询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 Cnoselect 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中选学多门课程的同学中分数为非最高分成绩的记录。

理解1select * 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) 理解2select * 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='女' unionselect 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

你可能感兴趣的文章
面向对象
查看>>
lintcode83- Single Number II- midium
查看>>
移动端 响应式、自适应、适配 实现方法分析(和其他基础知识拓展)
查看>>
selenium-窗口切换
查看>>
selenium-滚动
查看>>
read from and write to file
查看>>
使用vue的v-model自定义 checkbox组件
查看>>
Amcharts 柱状图和线形图
查看>>
APC注入
查看>>
关于ES6 Class语法相关总结
查看>>
文件处理
查看>>
[工具] Sublime Text 使用指南
查看>>
Hangfire在ASP.NET CORE中的简单实现方法
查看>>
今晚的比赛(2011.12.4)
查看>>
统计细菌基因组ORF
查看>>
Unity3D笔记 英保通三 脚本编写 、物体间通信
查看>>
python实现对某招聘网接口测试获取平台信息
查看>>
Algorithm——何为算法?
查看>>
Web服务器的原理
查看>>
小强升职计读书笔记
查看>>