PHP数据库45道题整理~~~啦啦啦
select * FROM student
-- 二:查询student表中所有记录
select * FROM score WHERE Degree>60 AND Degree<80
-- 四:查询Score表中成绩在60到80之间的所有记录
SELECT * FROM score WHERE Degree in ('85','86','88');
-- 五:查询Score表中成绩为85,86或88的记录。
SELECT * FROM student WHERE Class = '95031' AND Ssex = '0';
-- 查询Student表中“95031”班或性别为“女”的同学记录。
SELECT * FROM student ORDER BY Class;
-- 以Class降序查询Student表的所有记录。
SELECT SUM(class = 95031) FROM student;
-- 查询“95031”班的学生人数。、
SELECT avg(Degree) FROM score;
-- 查询“95033”班学生的平均分。
SELECT Cno FROM score GROUP BY Cno
-- 先分组
SELECT avg(Degree) FROM score GROUP BY Cno
-- 然后用平均查询每门课的平均成绩。select
SELECT * FROM score where Cno = 3-105 AND Degree > 109
-- 19、 查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
select distinct Depart from Teacher
-- 查询教师所有的单位即不重复的Depart列。
select Cno,avg(degree) from Score where cno like '3%' group by Cno having count(Cno)>5;
-- 12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select Sno from score where Degree >70 and Degree<90
-- 13、查询分数大于70,小于90的Sno列。
SELECT * FROM student QWE JOIN score ZXC ON QWE.Sno=ZXC.Sno;
-- 合并表格,将student和score进行合并 左右连接在join前面加上left or RIGHT;
create table grade(low int(3),upp int(3),rank char(1))
insert into grade values(90,100,'A')
insert into grade values(80,89,'B')
insert into grade values(70,79,'C')
insert into grade values(60,69,'D')
insert into grade values(0,59,'E')
-- 简历grade表格
SELECT * FROM score WHERE Sno = 109 AND Cno = 3-105;
-- 以下
-- 41、查询“男”教师及其所上的课程。
select Cname from course where Tno in (select Tno from teacher where Tsex='1');
select Tname,Cname from course,teacher where course.Tno = teacher.Tno and teacher Tsex='1';
select Tname,Cname from course,teacher where course.Tno=teacher.Tno and teacher.Tsex='1';
-- 44、查询和“李军”同性别并同班的同学Sname.
select sname from Student where Ssex=(select Ssex from Student where Sname='李军')and class=(select Class from Student where Sname='李军')
14、查询所有学生的Sname、Cno和Degree列。
select Sname,Cno,degree from score join student on score.sno =student.sno ---连接查询
15、查询所有学生的Sno、Cname和Degree列。
select Sname,Sno,degree from Score join course on Score.Cno =Course.Cno
16、查询所有学生的Sname、Cname和Degree列。
select cname,sname,Degree from score join student on student.sno=score.sno join course on score.cno=course.cno
select cname,sname,degree from score ,student,course where student.sno=score.sno and score.cno=course.cno
-- 19、现查询所有同学的Sno、Cno和rank列。
select sno,cno,rank from score ,grade where score.degree between low and upp
-- 20、查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105')
select * from score where cno='3-105' and degree >(select max(degree) from score where sno=’109’)
-- 21、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
select * from score where sno in (select sno from score group by sno having count(*)>1) and degree <(select max(degree) from score )
select * from score a where sno in (select sno from score group by sno having count(*)>1) and degree <(select max(degree) from score b where b.cno=a.cno )
-- 22、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105')
-- 23、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
select * from student where year(sbirthdy)=(select year(sbirthday) from student where sno='108')
-- 24、查询“张旭“教师任课的学生成绩。
select Degree from Score where Cno in (select Cno from Course where Tno in (select Tno from Teacher where Tname='张旭'))
-- 25、查询选修某课程的同学人数多于5人的教师姓名。
select tname from teacher where tno in (select tno from Course where Cno in (select Cno from Score group by Cno having COUNT(*)>5))
-- 26、查询95033班和95031班全体学生的记录。
select * from Student where Class='95033' or class='95031'
select * from student where class in('95033','95031')
-- 27、查询存在有85分以上成绩的课程Cno.
select distinct cno from Score where Degree>85
-- 28、查询出“计算机系“教师所教课程的成绩表。
select * from Score where Cno in(select Cno from Course where Tno in(select tno from Teacher where Depart='计算机系'))
-- 29、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
select tname,prof from Teacher where Depart= '计算机系' and prof not in(select prof from Teacher where Depart='电子工程系')
union
select tname,prof from Teacher where Depart= '电子工程系' and prof not in(select prof from Teacher where Depart='计算机系')
select tname,prof from teacher a where prof not in (select prof from teacher b where b.depart!=a.depart)
-- 30、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
select * from Score where cno='3-105' and degree>any(select degree from Score where cno='3-245')order by degree desc——any其中任何一个、all所有
-- 31、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.
select Cno,Sno,Degree from Score where cno='3-105' and degree>(select max(degree) from Score where cno='3-245')
-- 32、查询所有教师和同学的name、sex和birthday.
select tname,tsex,tbirthday from Teacher
-- 二:
select Sname,Ssex,Sbirthday from Student
-- 33、查询所有“女”教师和“女”同学的name、sex和birthday.
-- student
select Sname,Ssex,Sbirthday from Student where Ssex='0';
-- teacher
select tname,tsex,tbirthday from Teacher where Tsex='0';
-- 34、查询成绩比该课程平均成绩低的同学的成绩表。
Select * from score a where degree<(select avg(degree) from score b where a.cno=b.cno);
-- 35、 查询所有任课教师的Tname和Depart.
Select tname,depart from teacher where tno in (select tno from course where cno in (select cno from score group by cno))
Select tname,depart from teacher where tno in (select tno from course where cno in (select distinct cno from score))
-- 36、查询所有未讲课的教师的Tname和Depart.
Select tname,depart from teacher where tno in (select tno from course where cno not in (select distinct cno from score))
-- 37、查询至少有2名男生的班号。
select class from student where Ssex='1' group by Class having count(*) >1;
-- 38、查询Student表中不姓“王”的同学记录。
select sname from Student where Sname not like '王%';
-- 39题不会写,重点在年,year;
-- 39、查询Student表中最大和最小的Sbirthday日期值。
select MAX(sbirthday) as '最大值',MIN(sbirthday)'最小值' from Student
-- 40、以班号和年龄从大到小的顺序查询Student表中的全部记录。
select class,sbirthday from Student order by Class desc,Sbirthday asc
-- 41、查询“男”教师及其所上的课程。
select cname from course where tno in(select tno from teacher where tsex=’男’)
select tname,cname from teacher ,course where teacher.tno=course.tno and tsex='男'
-- 42、查询最高分同学的Sno、Cno和Degree列。
(1)select * from score where Degree = (select max(Degree) from score)
(2)select top 1 * from score order by degree desc
-- 43、查询和“李军”同性别的所有同学的Sname.
select sname from Student where Ssex=(select Ssex from Student where Sname='李军')
-- 44、查询和“李军”同性别并同班的同学Sname.
select sname from Student where Ssex=(select Ssex from Student where Sname='李军')and class=(select Class from Student where Sname='李军');
-- 45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
select Degree from score where Sno in(select Sno from student where Ssex='1') and Cno in (select Cno from course where Cname = '计算机导论');
PHP数据库45道题整理~~~啦啦啦的更多相关文章
- 2017-3-18 SQL server 数据库 45道题
use data02161212 create table student (Sno nvarchar(3) primary key, Sname nvarchar(8) not null, Ssex ...
- 单元测试系列之八:Sonar 数据库表关系整理一(续)
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 简介:Sonar平台是目前较为流行的静态代码扫描平台,为了便于使用以及自己二次开发,有必要对它的数据库结构进行学习 ...
- 单元测试系列之七:Sonar 数据库表关系整理一(rule相关)
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/7510072.html 简介:Sonar ...
- (转)Mysql数据库主从心得整理
Mysql数据库主从心得整理 原文:http://blog.sae.sina.com.cn/archives/4666 管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本 ...
- MySQL数据库字符集和整理
MySQL数据库字符集和整理(2009-11-20 22:23:37) mysql数据库 it 其实这个表在MySQL数据库中通过phpMyAdmin就能看到,icech只是把表格整理了一下方便 ...
- SQL Server T—SQL 学生选课数据库SQL语句考试题(45道题)
题目 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1 ...
- 2017年10月29日 数据库查询总结&45道题
日期函数: 当前时间:GetDate() 两个时间差:DateDiff() 一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Tea ...
- Oracle数据库sql命令整理
转至:https://blog.csdn.net/weixin_43712330/article/details/88358604 以下为oracle数据库中sql语句的整理,将持续更新01. 如何登 ...
- TSQL查询45道题
一.设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1- ...
随机推荐
- 关于php中的include html文件的问题,为什么html可以在php中执行
之前在w3shXXl看的教程,上面对include的解释是把指定的文件复制到这条指令执行的地方. 这真是坑到我了..... 在了解mvc的时候,控制器显示视图时需要用include包含html视图文件 ...
- multisim&proteus&protel比较
Multisim有超强板级的模拟/数字电路板的设计工作.它包含了电路原理图的图形输入.电路硬件描述语言输入方式,具有丰富的仿真分析能力.高版本可 以进行单片机等MCU的仿真.Multisim有实际元器 ...
- 传参时Url中有中文报错
url中如果传了中文,浏览器会报错:The header content contains invalid characters. 原因:浏览器自动把这个url进行decodeURIComponent ...
- jboss初体验
本人电脑的java版本是java8,而jboss的版本最多支持到java7.x,导致启动jboss7,在浏览器无法访问localhost:8080. 于是我查找百度,发现jboss8其实就是wildf ...
- python进阶学习(四)
在使用多线程之前,我们首页要理解什么是进程和线程. 什么是进程? 计算机程序只不过是磁盘中可执行的,二进制(或其它类型)的数据.它们只有在被读取到内存中,被操作系统调用的时候才开始它们的生命期.进程( ...
- HDU 6185 Covering 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6185 题意:用 1 * 2 的小长方形完全覆盖 4 * n的矩形有多少方案. 解法:小范围是一个经典题 ...
- setAttribute设置无效
我发现ie浏览器中动态用setAttribute设置style属性值始终不能设置,经过一番查找发现了这篇文字 http://webcenter.hit.edu.cn/articles/2009/05- ...
- 图论中DFS与BFS的区别、用法、详解…
DFS与BFS的区别.用法.详解? 写在最前的三点: 1.所谓图的遍历就是按照某种次序访问图的每一顶点一次仅且一次. 2.实现bfs和dfs都需要解决的一个问题就是如何存储图.一般有两种方法:邻接矩阵 ...
- MPLS VPN随堂笔记1
MPLS VPN 基础 1.MPLS vpn架构的特点 1.1.允许不同CE传递相同私网路由 1.2.SP内部(所有P路由器)不需要学习CE路由 1.3.无安全保障但有带宽保障(跟SP租用服务) 2. ...
- CCIE-MPLS VPN-实验手册(中卷)
5:MPLS VPN PE CE OSPF 实验1 5.1 实验拓扑 5.2 实验需求 a. R1 R2 R3 组成P-NETWORK,底层协议采用EIGRP b. R1 R2 R3 直连链路启用LD ...