mysql课程表学时_Mysql 巩固提升 (学生表_课程表_成绩表_教师表)

方便Mysql 巩固提升

创建表并插入数据:

-- ----------------------------

-- Table structure for student

-- ----------------------------

DROP TABLE IF EXISTS `student`;

CREATE TABLE `student` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`sname` varchar(32) DEFAULT NULL,

`sage` int(11) DEFAULT NULL,

`ssex` varchar(8) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of student

-- ----------------------------

INSERT INTO `student` VALUES ('1', '刘一', '18', '男');

INSERT INTO `student` VALUES ('2', '钱二', '19', '女');

INSERT INTO `student` VALUES ('3', '张三', '17', '男');

INSERT INTO `student` VALUES ('4', '李四', '18', '女');

INSERT INTO `student` VALUES ('5', '王五', '17', '男');

INSERT INTO `student` VALUES ('6', '赵六', '19', '女');

-- ----------------------------

-- Table structure for teacher

-- ----------------------------

DROP TABLE IF EXISTS `teacher`;

CREATE TABLE `teacher` (

`id` int(11) DEFAULT NULL,

`tname` varchar(16) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of teacher

-- ----------------------------

INSERT INTO `teacher` VALUES ('1', '叶平');

INSERT INTO `teacher` VALUES ('2', '贺高');

INSERT INTO `teacher` VALUES ('3', '杨艳');

INSERT INTO `teacher` VALUES ('4', '周磊');

-- ----------------------------

-- Table structure for course

-- ----------------------------

DROP TABLE IF EXISTS `course`;

CREATE TABLE `course` (

`id` int(11) DEFAULT NULL,

`cname` varchar(32) DEFAULT NULL,

`tid` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of course

-- ----------------------------

INSERT INTO `course` VALUES ('1', '语文', '1');

INSERT INTO `course` VALUES ('2', '数学', '2');

INSERT INTO `course` VALUES ('3', '英语', '3');

INSERT INTO `course` VALUES ('4', '物理', '4');

-- ----------------------------

-- Table structure for sc

-- ----------------------------

DROP TABLE IF EXISTS `sc`;

CREATE TABLE `sc` (

`sid` int(11) DEFAULT NULL,

`cid` int(11) DEFAULT NULL,

`score` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------

-- Records of sc

-- ----------------------------

INSERT INTO `sc` VALUES ('1', '1', '56');

INSERT INTO `sc` VALUES ('1', '2', '78');

INSERT INTO `sc` VALUES ('1', '3', '67');

INSERT INTO `sc` VALUES ('1', '4', '58');

INSERT INTO `sc` VALUES ('2', '1', '79');

INSERT INTO `sc` VALUES ('2', '2', '81');

INSERT INTO `sc` VALUES ('2', '3', '92');

INSERT INTO `sc` VALUES ('2', '4', '68');

INSERT INTO `sc` VALUES ('3', '1', '91');

INSERT INTO `sc` VALUES ('3', '2', '47');

INSERT INTO `sc` VALUES ('3', '3', '88');

INSERT INTO `sc` VALUES ('3', '4', '56');

INSERT INTO `sc` VALUES ('4', '2', '88');

INSERT INTO `sc` VALUES ('4', '3', '90');

INSERT INTO `sc` VALUES ('4', '4', '93');

INSERT INTO `sc` VALUES ('5', '1', '46');

INSERT INTO `sc` VALUES ('5', '3', '78');

INSERT INTO `sc` VALUES ('5', '4', '53');

INSERT INTO `sc` VALUES ('6', '1', '35');

INSERT INTO `sc` VALUES ('6', '2', '68');

INSERT INTO `sc` VALUES ('6', '4', '71');

1. 查询“001”课程比“002”课程成绩高的所有学生的学号

SELECT

a1.sid

FROM

(SELECT * FROM sc WHERE cid = 1) a1,

(SELECT * FROM sc WHERE cid = 2) a2

WHERE

a1.score > a2.score

AND a1.sid = a2.sid

select sid,GROUP_CONCAT(score),count(sid)from sc GROUP BY sid;

2. 查询平均成绩大于60分的学生的平均成绩

select sid,AVG(score) from sc GROUP BY sid HAVING AVG(score)>60;

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

select a1.id,a1.sname from student a1;

select sid,count(cid),sum(score) from sc GROUP BY sid;

SELECT

a1.id,

a1.sname,

a2.number,

a2.score

FROM

student a1,

(

SELECT

sid,

count(cid) AS number,

sum(score) AS score

FROM

sc

GROUP BY

sid

) a2

WHERE

a1.id = a2.sid;

4. 查询姓“周”的老师的个数

SELECT

count(DISTINCT(tname))

FROM

teacher

WHERE

tname LIKE '周%';

5.查询没学过“叶平”老师课的同学的学号、姓名

select id from course a where a.tid = (SELECT id from teacher where tname='叶平');

select sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid;

SELECT

sid

FROM

(

SELECT

sid,

GROUP_CONCAT(cid ORDER BY cid ASC) AS cids

FROM

sc

GROUP BY

sid

) a

WHERE

! FIND_IN_SET('1', cids);

6. 查询学过“001”并且也学过编号“002”课程的同学的学号、姓名

方法一:

select sid from (select sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid) a where FIND_IN_SET('1',cids) and FIND_IN_SET('2',cids);

SELECT id,sname from student where student.id in (select sid from (select sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid) a where FIND_IN_SET('1',cids) and FIND_IN_SET('2',cids));

方法二:

select student.id,student.sname from student,sc where student.id = sc.sid and sc.cid = '001' and EXISTS(select * from sc sc2 where sc.sid = sc2.sid and sc2.cid='002');

7.查询学过“叶平”老师所教的所有课的同学的学号、姓名

SELECT student.id,student.sname from student where student.id in(SELECT DISTINCT(sid) from sc,course,teacher WHERE sc.cid = course.id and course.id = teacher.id and teacher.tname = '叶平');

8. 查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名

select a2.sid from (select * from sc where sc.cid ='002') a1,(select * from sc where sc.cid ='001') a2 where a1.score < a2.score and a1.sid = a2.sid;

select student.id,student.sname from student where student.id in(select a2.sid from (select * from sc where sc.cid ='002') a1,(select * from sc where sc.cid ='001') a2 where a1.score < a2.score and a1.sid = a2.sid)

9. 查询所有课程成绩小于60分的同学的学号、姓名

select GROUP_CONCAT(score ORDER BY score asc) from sc GROUP BY sid

select * from student where student.id not in(select sid from student,sc where student.id = sc.sid and sc.score>60);

10.查询没有学全所有课的同学的学号、姓名

SELECT count(1) from course;

SELECT sid from sc GROUP BY sid HAVING count(cid)

select a.id,a.sname from student a,(SELECT sid from sc GROUP BY sid HAVING count(cid)

select a.id,a.sname from student a,sc b where a.id = b.sid GROUP BY a.id HAVING count(a.id)<4;

11.查询至少有一门课与学号为“1001”的同学所学相同的同学的学号和姓名

select DISTINCT(student.id),student.sname from student,sc where student.id = sc.sid and sc.cid in(SELECT sc.cid from sc where sc.sid='1');

12.把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩

select course.id from course,teacher where course.tid = teacher.id and teacher.tname ='叶平';

select sc.cid,avg(score) from sc where sc.cid= 1 GROUP BY cid;

UPDATE sc set sc.score = 12 where sc.cid =5;

13.查询和“1002”号的同学学习的课程完全相同的其他同学学号和姓名

SELECT sc.sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid;

SELECT cids from (SELECT sc.sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid) a where a.sid = 1;

select * from (SELECT sc.sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid) a where a.cids = (SELECT cids from (SELECT sc.sid,GROUP_CONCAT(cid ORDER BY cid ASC) as cids from sc GROUP BY sid) a where a.sid = 1);

14.删除学习“叶平”老师课的SC表记录

SELECT * from sc,course,teacher where sc.cid = course.id and course.id = teacher.id and teacher.tname = '叶平';

15.查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分

SELECT cid,MAX(score) as '最高分',MIN(score) as '最低分' from sc GROUP BY sc.cid

select cid,GROUP_CONCAT(score) from sc GROUP BY cid;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/529524.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

初始java_第一章__初始JAVA

1.java的三个发展方向&#xff1a;JAVASE(面向对象、API、JVM)、JAVAME(移动设备、游戏、通信)、JAVAEE(JSP、EJB、服务)2.开发JAVA的程序步骤&#xff1a;1.编写源程序 2.编译 3.运行3.JDKJRE开发工具下载java环境jdk 安装并配置环境变量&#xff0c;.安装直接下一步下一步直到…

python最常用的版本、也称为classic_2021年中国大学《创新思维与创业》单元测试答案...

2021年中国大学《创新思维与创业》单元测试答案被人们称为 “寒地水稻第一人”的是袁隆平答&#xff1a;错地图数据的基本特征包括答&#xff1a;时间属性 空间定位属性 地理属性对卖方征税导致商品价格上升答&#xff1a;√( )是在床榻上使用的一种矮形家具。答&#xff1a;炕…

java 泛型 继承_java基础之泛型的继承

关于泛型的基本介绍和理解请参考以下几篇文章&#xff0c;或查询更多资料&#xff1a;本篇以简单的List<>方式来进行说明。ArrayList继承了List,ArrayList没有继承ListList>等价于List extends Object>请参考以下代码&#xff1a;/*** author Ding Chengyun* 2014-…

appium java环境_Appium环境搭建(Windows版)

注&#xff1a;appium安装到C盘&#xff0c;node.js安装到C盘一、安装node.js1、到官网下载node.js&#xff1a;https://nodejs.org/en/download/2、获取到安装文件后&#xff0c;直接双击安装文件&#xff0c;根据程序的提示&#xff0c;完成nodejs的安装。3、安装完成后&…

ci mysql pdo_CI框架中pdo的使用方法

1、配置文件修改application/config文件夹下的database.php文件 $db[default] array(dsn > mysql:dbnameci_ecshop;host127.0.0.1,username > root,password > ,dbdriver > pdo,2、查询操作$sql select * from aaa where id :id;$sql_array array(:id > …

ie11加载java插件_IE浏览器中ActiveX插件的使用

在某些行业的B/S应用系统中会不可避免的要用到ActiveX浏览器插件&#xff0c;而ActiveX插件只能在IE内核浏览器中运行&#xff0c;而常用的IE浏览器的版本众多&#xff0c;从IE6到IE11&#xff0c;总共有6个版本&#xff0c;这就给开发的应用系统造成了不小的困扰&#xff1a;如…

netty java开发文档_Netty简明教学文档

写个简单点&#xff0c;比较小白的文档&#xff0c;言语比较接地气Netty是什么&#xff1f;NIO的高层封装&#xff0c;NIO很难写&#xff0c;所以有了Netty&#xff0c;方便异步的操作service的主要代码片段public void run() throws Exception {EventLoopGroup bossGroup new…

mysql 全局不重复_php uniqid() 通过MYSQL实现全局不重复的唯一ID

看了国外文章&#xff1a;https://jason.pureconcepts.net/2013/09/php-convert-uniqid-to-timestamp/ 不想写&#xff50;&#xff48;&#xff50;脚本uniqid()处理&#xff0c;想到用mysql一次性把数据库的ID改过来的方法&#xff0c;所以开始了以下研究方法一: 效率最高&…

java接口允许ajax访问_服务允许AJAX请求,允许跨域请求

当工作时间&#xff0c;因为需要JS 进行AJAX请求&#xff0c;这时候存在跨域问题&#xff0c;当出现这种情况时&#xff0c;有多种方案解决比如使用JSONP&#xff0c;也有一种简单的方式&#xff0c;就是在过滤器里面增加返回请求允许跨域head配置。代码如下&#xff1a;/**** …

mysql的增_MySQL之增_insert-replace

MySQL增删改查之增insert、replace一、INSERT语句带有values子句的insert语句&#xff0c;用于数据的增加语法&#xff1a;INSERT [INTO] tbl_name[(col_name,...)]{VALUES | VALUE} (expr ,...),(...),...①用来把一个新行插入到表中②为和其它数据库保持一致&#xff0c;不要…

python manager详解_python 多进程共享全局变量之Manager()详解

Manager支持的类型有list,dict,Namespace,Lock,RLock,Semaphore,BoundedSemaphore,Condition,Event,Queue,Value和Array。但当使用Manager处理list、dict等可变数据类型时&#xff0c;需要注意一个陷阱&#xff0c;即Manager对象无法监测到它引用的可变对象值的修改&#xff0c…

java 添加等待时间_Java中线程等待特定时间的最有效方法 - java

我知道这个问题here&#xff0c;但是我有一个稍微不同的问题。如果我希望自己通过各种Thread方法(而不是通过实用程序类或Quartz)手动编码某个线程在特定时间的运行&#xff0c;那么最有效(就开销而言)进行编码。我考虑过:boolean wasInterrupted false;while (System.current…

PHP微信app接口退款,10.PHP接入微信退款接口

推荐文章摘要环境搭建开启配置服务器环境核心类验证回复拓展推荐文章今天网上和朋友圈炸开了锅&#xff0c;原因是微信小程序正式上线了。吃瓜群众表示不理解&#xff0c;于是去搜了下。不搜不要紧&#xff0c;搜了吓一跳&#xff0c;原来微信小程序早在2016年9月份就已经进行了…

java线程读取流的时候卡死,java – 线程中断没有结束阻塞调用输入流读取

我正在使用RXTX从串口读取数据.读取是在以下列方式生成的线程内完成的&#xff1a;CommPortIdentifier portIdentifier CommPortIdentifier.getPortIdentifier(port);CommPort comm portIdentifier.open("Whatever", 2000);SerialPort serial (SerialPort)comm;..…

php poi,GitHub - satthi/poi-php: poi-php

poi-phpvarsion 0.1(2013/10/21)このプラグインはJavaのpoiをPHPから叩いてエクセルを入出力するプラグインです。必須要件jdk1.7.0_40poi-3.9opencsv-2.3使い方①poi-phpを任意の場所に設置②PHPを記述//デフォルト読み込みrequire_once(poi-php.phpのディレクトリパス);$this…

php hmac sha256签名,HMAC-SHA256签名错误?

#2.连接商户key&#xff1a;act_name3333321ss&client_ip118.89.65.223&mch_billnoa0000000000000000001&mch_id1529243621&nonce_str905Qh0J59d69JjDtD7QkyRAm576kh5hU&re_openidoiW0l03-60UfHJfo0olLt3wOLb0E&remark111&remark222dddd&send_…

php传输的多个id集中为一条记录,如何将多个ID应用于Mysql中的一条记录?

在实体关系语言中,这称为多对多关系.一个产品可以有多个类别,一个类别可以有多个产品.要在关系数据库中执行此操作,您需要三个表.product: product_id, name, description, etccategory: category_id, catname, catdescription, etc然后用这个所谓的联接表建立产品和类别之间的…

php redis 传递闭包,通过缓存构建高性能 Laravel 应用

通过缓存构建高性能 Laravel 应用由 学院君 创建于3年前, 最后更新于 11个月前版本号 #220678 views9 likes1 collects配置Laravel 为不同的缓存系统提供了统一的 API。缓存配置位于 config/cache.php。在该文件中你可以指定在应用中默认使用哪个缓存驱动。Laravel 开箱支持主流…

imclearboder matlab,Lucas

Lucas-Kanade跟踪算法是视觉跟踪中一个很经典的基于点的逐帧跟踪算法。起初这个算法是用来求解stero matching1的&#xff0c;后来经过Carlo Tomasi2和Jianbo Shi3等人的发展渐趋成熟。Jianbo Shi提出了一种筛选跟踪点特征的方法&#xff0c;使得特征的跟踪更可靠。Jean-Yves B…

php判断url参数为空,PHP检查url链接是否已经有参数的简单示例

这篇文章主要为大家详细介绍了PHP检查url链接是否已经有参数的简单示例&#xff0c;具有一定的参考价值&#xff0c;可以用来参考一下。感兴趣的小伙伴&#xff0c;下面一起跟随512笔记的小编小韵来看看吧&#xff01;比如分页&#xff0c;因为有些链接已经有参数了&#xff0c…