当前位置: 首页 > 编程日记 > 正文

经典SQL练习题

题目地址:http://blog.csdn.net/qaz13177_58_/article/details/5575711

1、 查询Student表中的所有记录的Sname、Ssex和Class列。
select sname,ssex,class from STUDENT
2、 查询教师所有的单位即不重复的Depart列。
select depart from TEACHER group by depart
select distinct depart from teacher
3、 查询Student表的所有记录。
select * from student
4、 查询Score表中成绩在60到80之间的所有记录。
select * from score where degree between 60 and 80
5、 查询Score表中成绩为85,86或88的记录。
select * from score where degree in(85,86,88)
6、 查询Student表中“95031”班或性别为“女”的同学记录。
select * from student where class='95031' or ssex='女'
7、 以Class降序查询Student表的所有记录。
select * from student order by class desc
8、 以Cno升序、Degree降序查询Score表的所有记录。
select * from score order by cno asc,degree desc
9、 查询“95031”班的学生人数。
select count(*) from student where class='95031'
10、查询Score表中的最高分的学生学号和课程号。
select sno,cno from score where degree=(select max(degree) from score)
select sno,cno from score where degree=(select top 1 degree from score order by degree desc)
11、查询‘3-105’号课程的平均分。
select avg(degree) from score where cno='3-105'
12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
select avg(degree) from score where cno like '3%' group by cno having count(sno)>=5
13、查询最低分大于70,最高分小于90的Sno列。
select sno from score group by sno having min(degree)>70 and max(degree)<90
14、查询所有学生的Sname、Cno和Degree列。
select s.SNAME,c.CNO,c.DEGREE from score c inner join student s on c.SNO=s.SNO
15、查询所有学生的Sno、Cname和Degree列。
select s.sno,c.cname,s.degree from score s inner join course c on s.CNO=c.CNO
16、查询所有学生的Sname、Cname和Degree列。
select st.SNAME,cu.CNAME,sc.DEGREE from student st inner join score sc on st.SNO=sc.SNO inner join course cu on sc.CNO=cu.CNO
17、查询“95033”班所选课程的平均分。
select avg(degree) from score where sno in(select sno from STUDENT where class='95033')
SELECT AVG(A.DEGREE) FROM SCORE A JOIN STUDENT B ON A.SNO = B.SNO WHERE B.CLASS='95033'
18、假设使用如下命令建立了一个grade表:
create table grade(low int,upp int,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');
现查询所有同学的Sno、Cno和rank列。
select sno,cno,(select rank from grade where degree between low and upp) from score
19、查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105')
20、查询score中选学一门以上课程的同学中分数为非最高分成绩的记录。
select * from score where sno in(select sno from score where degree<(select MAX(degree) from score) group by sno having COUNT(*)>1) order by degree desc
21、查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
select * from score where degree>(select degree from score where sno='109' and cno='3-105')
22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
select sno,sname,sbirthday from student where Year(sbirthday)=(select Year(sbirthday) from student where sno='108')
23、查询“张旭“教师任课的学生成绩。
select sno,degree from course c inner join teacher t on c.tno=t.tno inner join score s on s.cno=c.cno where tname='张旭'
select sno,degree from score where cno in(select cno from course where tno=(select tno from teacher where tname='张旭'))//感觉这里用in好一点,一个老师可能上多门课
24、查询选修某课程的同学人数多于5人的教师姓名。
select tname from teacher where tno=(select tno from course where cno in(select cno from score group by cno having count(cno)>5))
select t.tname from teacher t inner join course c on t.tno=c.tno left join score s on c.cno=s.cno group by t.tname having COUNT(*)>5
25、查询95033班和95031班全体学生的成绩记录。
select * from score where sno in(select sno from student where class in('95033','95031'))
26、查询存在有85分以上成绩的课程Cno.
select cno from score where degree>85 group by cno
select cno from score group by cno having max(degree)>85
27、查询出“计算机系“教师所教课程的成绩表。
select * from score where cno in(select cno from course where tno in(select tno from teacher where depart='计算机系'))
select * from score where cno in (select c.cno from course c join teacher t on c.tno=t.tno and t.depart='计算机系')
28、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
select tname,prof from teacher where depart='计算机系' and prof not in (select prof from teacher where depart='电子工程系');//网上答案,意思有点不对
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='计算机系')//应该相互职称不同
29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
select cno,sno,degree from score where cno='3-105' and degree>(select min(degree) from score where cno='3-245') order by degree desc
select cno,sno,degree from score where cno='3-105' and degree>any(select degree from score where cno='3-245') order by degree desc
30、查询选修编号为“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') order by degree desc
select cno,sno,degree from score where cno='3-105' and degree>all(select degree from score where cno='3-245') order by degree desc
31、查询所有教师和同学的name、sex和birthday。
select tname as name,tsex as sex,tbirthday as birthday from teacher union select sname as name,ssex as sex,sbirthday as birthday from student
32、查询所有“女”教师和“女”同学的name、sex和birthday。
select tname as name,tsex as sex,tbirthday as birthday from teacher where tsex='女' union select sname as name,ssex as sex,sbirthday as birthday from student where ssex='女'
33、查询成绩比该课程平均成绩低的同学的成绩表。
select * from score s inner join (select avg(degree) as avgScore,cno from score group by cno) t on s.CNO=t.CNO where s.DEGREE<t.avgScore
34、查询所有任课教师的Tname和Depart。
select t.tname,t.depart from course c inner join teacher t on c.tno=t.tno
35 查询所有未讲课的教师的Tname和Depart.。
select tname,depart from course c right join teacher t on c.tno=t.tno where c.cno is null//course左连接就不会有null的值了,必须右连接
select tname,depart from teacher t left join course c on c.tno=t.tno where c.cno is null
36、查询至少有2名男生的班号。
select class from student where ssex='男' group by class having count(sno)>=2
37、查询Student表中不姓“王”的同学记录。
select * from student where sname not like '王%'
38、查询Student表中每个学生的姓名和年龄。
select sname,datediff(year,sbirthday,getdate()) from student
select sname,year(getdate())-year(sbirthday) from student
39、查询Student表中最大和最小的Sbirthday日期值。
select max(sbirthday),min(sbirthday) from student
40、以班号和年龄从大到小的顺序查询Student表中的全部记录。
select * from student order by class desc,sbirthday asc//日期小年龄大
41、查询“男”教师及其所上的课程。
select * from course c inner join teacher t on c.tno=t.tno where tsex='男'
42、查询最高分同学的Sno、Cno和Degree列。
select * from score where degree=(select max(degree) from score)
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 * from score s inner join course c on s.cno=c.cno inner join student st on s.sno=st.sno where cname='计算机导论' and ssex='男'

转载于:https://www.cnblogs.com/T-J-D/p/4118522.html

相关文章:

php url模式在哪修改,php如何修改url

php如何修改url2020-07-03 12:15:40php修改url的方法&#xff1a;1、通过配置文件修改URL规则&#xff1b;2、设置URL伪静态&#xff0c;即限制伪静态的后缀&#xff1b;3、在配置文件中开启路由支持&#xff0c;并配置路由&#xff1b;4、将URL进行重写即可。PHP对URL设置一、…

国外十大最流行PHP框架排名

以下为十个目前最流行的基于MVC设计模式的PHP框架。1. YiiYii是一个基于组件的高性能的PHP的框架&#xff0c;用于开发大规模Web应用。Yii采用严格的OOP编写&#xff0c;并有着完善的库引用以及全面的教程。从MVC&#xff0c;DAO/ActiveRecord&#xff0c;widgets&#xff0c;c…

python_web框架

一、web框架 web框架&#xff1a; 自己完成socket的web框架&#xff1a;如&#xff0c;Tornado等由WSGI完成socket的web框架&#xff1a;如&#xff0c;Django、flash等两种实现过程&#xff1a; 第二种WSGI方式的&#xff0c;由于自带socket所以可直接写后端代码。 python标准…

g-gdb 调试多线程

代码调试工具gdb是一个能够让我们在工作中高效排查代码异常根源的利器。 在此将gdb针对多线程的调试方式做一个笔记&#xff0c;也方便后续回顾以及分享大家。 本文采用的是一个简单的多线程代码示例&#xff0c;同时调试是在mac上进行的 mac安装gdb brew install gdb即可 基…

php数据库html文本,关于php,mysql,html的数字分页和文本_php

请勿盗版&#xff0c;转载请加上出处http://blog.csdn.net/yanlintao1请勿盗版&#xff0c;转载请加上出处http://blog.csdn.net/yanlintao1首先进行样式展示希望对大家有所帮助&#xff0c;也希望大家给出意见和建议&#xff1a;第一种&#xff1a;数字分页第二种&#xff1a;…

WinDbg加载不同版本CLR

WinDbg调试.net2.0和.net4.0程序有所不同&#xff0c;因为.net4.0使用新版本的CLR。例如&#xff1a; mscoree.dll 变为 mscoree.dll 和 mscoreei.dll&#xff0c; mscorwks.dll 变为 clr.dll&#xff0c; mscorjit.dll 变为 clrjit.dll。 因此&#xff0c;在.net2.0加载mscorj…

交换机***工具——Yersinia

Yersinia是国外一款专门针对交换机执行第二层***的***工具。目前的版本是0.7.1。目前支持的操作系统及版本号如表1所示。表1 Yerdinia支持的操作系统操作系统名称版本号OpenBSD3.4 (pcap库版本至少0.7.2以上)Linux2.4.x和2.6.xSolaris5.8 64bits SPARCMac OSX10.4 Tiger (Intel…

Rocksdb 写流程,读流程,WAL文件,MANIFEST文件,ColumnFamily,Memtable,SST文件原理详解

文章目录前言Rocksdb写流程图WAL 原理分析概述文件格式查看WAL的工具创建WAL清理WALMANIFEST原理分析概述查看MANIFEST的工具创建 及 清除 MANIFEST文件内容CcolumnFamily 详解概述API介绍核心数据结构创建以及删除MEMTABLE 实现概述实现Rocksdb写入逻辑概述实现总结关于写的一…

react 入门

首先安装node.js环境 下载地址 https://nodejs.org/en/download/检查安装版本 进入命令行npm -v~~3. 安装react命令环境 npm install - g react-native-cli ~~~ 初始化项目 FirstAppreact-native init FirstApp 转载于:https://www.cnblogs.com/liu-ya/p/10511537.html

将字符串打乱输出

将字符串打乱输出 Dim i,mm,Str,StrPosition,NewStrStr  "1234567890"For i1 To Len(Str)    StrPosition  GetRandomMath(1,Len(Replace(Str,mm,"")))    Str  Replace(Str,mm,"")    mm  Mid(str,StrPosition,1)   …

php帝国系统调出图片内空,帝国CMS图集字段的大图,小图,说明的调用方法

本文实例讲述了帝国CMS图集字段的大图,小图,说明的调用方法。分享给大家供大家参考。具体方法如下&#xff1a;复制代码代码如下:$arr array();$arr $navinfor[morepic];$newarr explode(egetzy(rn),$arr);$count count(explode(egetzy(rn),$navinfor[morepic]));//图集的图…

static和global的区别

1.global在整个页面起作用。2.static只在function和class内起作用。global和$GLOBALS使用基本相同&#xff0c;但在实际开发中大不相同。global在函数产生一个指向函数外部变量的别名变量&#xff0c;而不是真正的函数外部变量&#xff0c;一但改变了别名变量的指向地址&#x…

vue 之 nextTick 与$nextTick

VUE中Vue.nextTick()和this.$nextTick()怎么使用&#xff1f; 官方文档是这样解释的&#xff1a; 在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法&#xff0c;获取更新后的 DOM。 虽然 Vue.js 通常鼓励开发人员沿着“数据驱动”的方式思考&#xff…

Linux创建线程时 内存分配的那些事

文章目录问题描述问题分析针对问题1 的猜测:针对问题2 的猜测:原理追踪总结问题描述 事情开始于一段内存问题&#xff0c;通过gperf工具抓取进程运行过程中的内存占用情况。 分析结果时发现一个有趣的事情&#xff0c;top看到的实际物理内存只有几兆&#xff0c;但是pprof统计…

mysql plsql循环语句吗,Oracle PLSQL 在游标中用while循环实例程序

Oracle PLSQL 在游标中用while循环实例程序Oracle PLSQL 在游标中用while循环实例程序Oracle PLSQL 在游标中用while循环实例程序declarecursor emp_cur is select * from emp;v_emp emp%rowType;beginopen emp_cur;while emp_cur%notfound --while肯定要跟loop一起用的 且是控…

【原创】Linux环境下的图形系统和AMD R600显卡编程(11)——R600指令集

1 低级着色语言tgsi OpenGL程序使用GLSL语言对可编程图形处理器进行编程&#xff0c;GLSL语言&#xff08;以下高级着色语言就是指GLSL&#xff09;是语法类似C的高级语言&#xff0c;在GLSL规范中&#xff0c;GLSL语言被先翻译成教低级的类汇编语言&#xff0c;然后被翻译成硬…

VBScript中InStr函数的用法

InStr([start, ]str1, str2[, compare]) [用途]&#xff1a;返回str2在str1中的位置。匹配成功时&#xff0c;返回值最小值为1&#xff0c;未匹配到时返回0。 [参数说明]&#xff1a; start:在str1中开始匹配的位置&#xff0c;1表示从头开始&#xff0c;不能为0或更小值。 可选…

洛谷P3122 [USACO15FEB]圈住牛Fencing the Herd(计算几何+CDQ分治)

题面 传送门 题解 题目转化一下就是所有点都在直线\(AxBy-C0\)的同一侧&#xff0c;也就可以看做所有点代入\(AxBy-C\)之后的值符号相同&#xff0c;我们只要维护每一个点代入直线之后的最大值和最小值&#xff0c;看看每条直线的最大最小值符号是否相同就好了 以最大值为例&am…

skiplist跳表的 实现

文章目录前言跳表结构时间复杂度空间复杂度高效的动态插入和删除跳表索引的动态更新总结详细实现前言 rocksdb 的memtable中默认使用跳表数据结构对有序数据进行的管理&#xff0c;为什么呢&#xff1f; 同时redis 也用跳表作为管理自己有序集合的数据结构&#xff0c;为什么…

php的反射作用是什么意思,php反射的作用是什么

反射是在PHP运行状态中&#xff0c;扩展分析PHP程序&#xff0c;导出或提取出关于类、方法、属性、参数等的详细信息&#xff0c;包括注释。这种动态获取的信息以及动态调用对象的方法的功能称为反射API。反射是操纵面向对象范型中元模型的API&#xff0c;其功能十分强大&#…

《BI项目笔记》用Excel2013连接和浏览OLAP多维数据集

《BI项目笔记》用Excel2013连接和浏览OLAP多维数据集 原文:《BI项目笔记》用Excel2013连接和浏览OLAP多维数据集用Excel2013连接和浏览OLAP多维数据集 posted on 2014-12-02 08:58 NET未来之路 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/lonelyxmas/p/413…

mac 拷贝文件时报错 8060 解决方案

解决如下&#xff1a; 即某文件夹下出现多重子目录&#xff0c;级数很多&#xff0c;删除多余的子文件夹即可。 至于如何产生的&#xff0c;有人说是xcode升级导致&#xff0c;不过没有见证 。我的不属于这类情况的。 &#xff08;参见&#xff1a;http://macosx.com/forums/ma…

C#连接数据库

VScode 配置C#环境 https://blog.csdn.net/qq_40346899/article/details/80955788VScode 配置C#开发环境 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;using System.Data; using System.Data.SqlCli…

C++ 中emplace_back和push_back差异

前言 最近看rocskdb源码&#xff0c;发现了大量的设计模式和C高级特性&#xff0c;特此补充一下&#xff0c;巩固基础。 问题描述 其中关于动态数组的元素添加&#xff0c;代码中基本将push_back抛弃掉了&#xff0c;全部替换为emplace_back进行元素的添加。 看了一下官网描…

[51单片机学习笔记ONE]-----LED灯的多种使用方法

一.交替闪烁8个LED灯&#xff0c;时间间隔为1s 1 /******************************************************2 实验名称&#xff1a; 交替闪烁8个LED灯,时间间隔1s3 实验时间&#xff1a; 2014年12月2日4 ******************************************************/…

php 伪协议 lfi,php://伪协议(I/O)总能给你惊喜——Bugku CTF-welcome to bugkuctf

今天一大早BugkuCTF 的welcome to bugkuctf 就给了我一发暴击&#xff1a;完全不会啊。。。光看源码就发现不知道怎么处理了&#xff0c;于是转向writeup求助。结果发现这是一道非常有营养的题目&#xff0c;赶紧记录一下。题目链接&#xff1a;http://123.206.87.240:8006/tes…

Pascal's Triangle

帕斯卡三角形&#xff0c;主要考察vector的用法。 vector<vector<int> > generate(int numRows){vector<vector<int> > result;vector<int> tmp;result.clear();tmp.clear();int i,j;if(numRows 0)return result;else if(numRows 1){tmp.push_…

SpringBoot请求转发与重定向

但是可能由于B网址相对于A网址过于复杂,这样搜索引擎就会觉得网址A对用户更加友好,因而在重定向之后任然显示旧的网址A,但是显示网址B的内容。在平常使用手机的过程当中,有时候会发现网页上会有浮动的窗口,或者访问的页面不是正常的页面,这就可能是运营商通过某种方式篡改了用户正常访问的页面。重定向,是指在Nginx中,重定向是指通过修改URL地址,将客户端的请求重定向到另一个URL地址的过程,Nginx中实现重定向的方式有多种,比如使用rewrite模块、return指令等。使用场景:在返回视图的前面加上。

SSO 单点登录和 OAuth2.0 有何区别?

此方法的缺点是它依赖于浏览器和会话状态,对于分布式或者微服务系统而言,可能需要在服务端做会话共享,但是服务端会话共享效率比较低,这不是一个好的方案。在单点登录的上下文中,OAuth 可以用作一个中介,用户在一个“授权服务器”上登录,并获得一个访问令牌,该令牌可以用于访问其他“资源服务器”上的资源。首先,SSO 主要关注用户在多个应用程序和服务之间的无缝切换和保持登录状态的问题。这种方法通过将登录认证和业务系统分离,使用独立的登录中心,实现了在登录中心登录后,所有相关的业务系统都能免登录访问资源。

【转】linux服务器性能查看

转载自https://blog.csdn.net/achenyuan/article/details/78974729 1.1 cpu性能查看 1、查看物理cpu个数&#xff1a; cat /proc/cpuinfo |grep "physical id"|sort|uniq|wc -l 2、查看每个物理cpu中的core个数&#xff1a; cat /proc/cpuinfo |grep "cpu cores…