首页 > 数据库 >mysql-sql-第十周

mysql-sql-第十周

时间:2024-06-15 12:59:14浏览次数:13  
标签:stunm 第十 students sql score tscore mysql where select

学习目标:

sql

学习内容:

31.查询所有同学的学生编号、学生姓名、选课总数、所有课程的成绩总和
联合查询不会显示没选课的学生(上接)

Select students.stunm,name,u.s,u.t from students ,(select stunm,sum(counm) s,sum(tscore) t from score group by stunm) u where u.stunm=students.stunm
在这里插入图片描述
需要显示没选课学生(显示为NULL),需要使用join
select s.stunm, s.name,r.u,r.t from ((select students.stunm,students.name from students )s left join (select sc.stunm, sum(sc.tscore) as u, count(sc.counm) as t from score sc group by sc.stunm)r on s.stunm = r.stunm);

在这里插入图片描述
32.查询" 2001 “课程比” 2002 "课程成绩高的学生的信息及课程分数
因为需要全部的学生信息,则需要在score表中得到符合条件的stunm后与students表进行join,可以left join 也可以 right join

CREATE TEMPORARY TABLE temp1 AS select stunm,tscore from score where counm=‘2001’

CREATE TEMPORARY TABLE temp2 AS select stunm,tscore from score where counm=‘2002’

CREATE TEMPORARY TABLE temp3 AS select a.stunm,a.tscore,b.tscore from temp1 a , temp2 b where a.stunm=b.stunm and a.tscore>b.tscore

ERROR 1060 (42S21): Duplicate column name ‘tscore’

CREATE TEMPORARY TABLE temp4 AS select stunm,tscore v from score where counm=‘2002’

CREATE TEMPORARY TABLE temp3 AS select a.stunm,a.tscore,b.v from temp1 a , temp4 b where a.stunm=b.stunm and a.tscore > b.v

Select * from temp3 left join students on temp3 .stunm=students.stunm
在这里插入图片描述
Select*from(select a.stunm,n,m from(select stunm,tscore m from score where counm=‘2001’) a ,(select stunm,tscore n from score where counm=‘2002’) b where a.stunm=b.stunm and a.m>b.n)c left join students on c.stunm=students.stunm

在这里插入图片描述
Select*from students right join (select a.stunm,ts1,ts2 from(select stunm,tscore as ts1 from score where score.counm=‘2001’ ) as a,(select stunm ,tscore as ts2 from score where score.counm=‘2002’) as b where a.stunm=b.stunm and a.ts1>b.ts2 ) c on students.stunm=c.stunm

在这里插入图片描述

学习时间:

1月-3月,每天一小时左右

学习产出:

一周一发

标签:stunm,第十,students,sql,score,tscore,mysql,where,select
From: https://blog.csdn.net/abend11/article/details/136417312

相关文章

  • 部署mysql-8.0.35
    第一步:卸载系统自带mariadb查看系统自带的Mariadb:rpm-qa|grepmariadb卸载系统自带的Mariadb:rpm-e--nodepsmariadb-libs-5.5.44-2.el7.centos.x86_64删除etc目录下的my.cnf:rm-rf/etc/my.cnf检查mysql是否存在:rpm-qa|grepmysql第二步:将下载的mysql安装包mysql-8.0.3......
  • MySQL导出数据库脚本
    1在Navicat中找到项目对应的数据库(如:booksystem)→右键转储SQL文件→结构和数据注意:information_schema、mysql、performance_schema、sys这4个库是MySQL自己的,不是你项目的,不要打开或破坏它们2在弹出的另存为对话框中选择一个位置并点击保存......
  • 【MySQL】事务一
    事务一1.什么是事务2.为什么会存在事务3.事务的版本支持4.事务的提交方式5.事务常见操作方式6.事务隔离级别6.1读未提交【ReadUncommitted】6.2读提交【ReadCommitted】6.3可重复读【RepeatableRead】6.4串行化【serializable】点赞......
  • 基于PHP+MySQL的宠物MeoWong Pets Caring Platform系统的设计与实现
    目录摘要IABSTRACT1目录1第1章引言11.1课题背景11.2研究现状11.3研究目标1第2章相关的理论和技术22.1HTML简介22.2PHP技术42.2.1PHP简介42.2.2PHP开发平台52.2.3PHP文件组成52.3访问数据库的实现方法52.4tomcat数据库连接池介绍......
  • mysql8.0授权root远程访问
     mysql8.0授权root远程访问要授权MySQL8.0的root用户远程访问,你可以按照以下步骤操作:登录到MySQL服务器:  mysql-uroot-p创建一个新的用户或者授权现有用户(如果已存在):  CREATEUSER'root'@'%'IDENTIFIEDBY'password';或者 ......
  • 传统后端SQL数据层替代解决方案: 内置数据源+JdbcTemplate+H2数据库 详解
    内置数据源我们回顾一下druid数据源的配置方式通过type属性指定数据源的类型导入依赖starter就使用了spring的自动装配功能格式二是在引入druid的依赖的基础上进行的一种配置方式Tomcat内部也可以进行数据源的配置轻量级中最快的数据源对象我们切换德鲁伊连接池......
  • 116. 小欧的卡牌(卡码网周赛第十七期(23年oppo提前批B组笔试真题))
    116.小欧的卡牌(卡码网周赛第十七期(23年oppo提前批B组笔试真题))题目描述小欧有n张卡牌,第i张卡牌的正面写了个数字ai,背面写了个数字bi。小欧对于每张卡牌可以选择一面向上,她希望最终向上的数字之和为3的倍数。你能告诉小欧有多少方案吗?由于答案过大,请对10^9+7......
  • 115. 组装手机(卡码网周赛第十七期(23年oppo提前批B组笔试真题))
    115.组装手机(卡码网周赛第十七期(23年oppo提前批B组笔试真题))题目描述小欧是手机外壳供应商,小蕊是手机零件供应商。小欧已经生产了n个手机外壳,第i个手机外壳售价ai元,小蕊生产了n个手机零件,第i个手机零件售价bi元。在组装手机中,一个手机外壳与一个手机零件可......
  • MySQL 5.7贴心参数之binlog_row_image=full
    相信大家都了解mysqlbinlog的格式,那就是有三种,分别是STATEMENT,MiXED,ROW。各有优劣,具体的请大家自行查阅资料。在MySQL5.7版本以前,虽然ROW格式有各种各样的好处。1.比如加快从库重放日志;ROW直接调用mysql的存储引擎接口(handlerAPI)来执行行的插入、删除和更新,完全跳......
  • 更改MySQL服务名称
    参考——https://blog.csdn.net/weixin_47916959/article/details/131441500 打算把mysql服务的名字从MySQL改成MySQL8(注意要在关闭了MySQL服务的前提下操作)以管理员身份运行命令提示符(不会管理员运行的可以参考这个——https://www.cnblogs.com/yansans/p/1824882......