mysql--学生课程成绩表
创建表student:
CREATE TABLE `student` (
`sid` INT(11) NOT NULL AUTO_INCREMENT,
`sname` VARCHAR(20) NOT NULL DEFAULT '0',
`sage` INT(11) NOT NULL DEFAULT '0',
`sex` VARCHAR(10) NOT NULL DEFAULT '0',
`sdept` VARCHAR(20) NULL DEFAULT NULL,
PRIMARY KEY (`sid`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
创建表course:
CREATE TABLE `course` (
`cid` INT(11) NOT NULL AUTO_INCREMENT,
`cname` VARCHAR(20) NOT NULL DEFAULT '0',
`ccredit` INT(11) NOT NULL DEFAULT '0',
`semester` INT(11) NOT NULL DEFAULT '0',
`period` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`cid`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=3;
创建表sc:
CREATE TABLE `sc` (
`sid` INT(11) NOT NULL DEFAULT '0',
`cid` INT(11) NOT NULL DEFAULT '0',
`score` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`sid`, `cid`),
CONSTRAINT `FK_sc_course` FOREIGN KEY (`cid`) REFERENCES `course` (`cid`),
CONSTRAINT `FK_sc_student` FOREIGN KEY (`sid`) REFERENCES `student` (`sid`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
查询:
1. 计算机系人名字和年龄:
select sname, sage from student where sdept="computer"
2. 数学成绩在80到100之间的名字和学科和分数:
select sname,cname,score from student s, course c, sc where s.sid=sc.sid and c.cid=sc.cid and sc.score between 80 and 100 and cname="数学"
3. 每个系多少学生:
select count(sdept),sdept from student group by sdept
4. 课程1比课程2分数高的学号:
select a.sid from(select sid, score from sc where cid=1)a, (select sid,score from sc where cid=2)b
where a.score>b.score and a.sid=b.sid
5. 平均分大于80分的学号和平均分:
select sid, avg(score) from sc group by sid having avg(score)>70
6. 所有学生的学号, 姓名, 选课数, 总成绩:
select student.sid, sname, count(sc.cid),sum(sc.score) from student left outer join sc on student.sid=sc.sid group by student.sid;
7.
mysql--学生课程成绩表的更多相关文章
- Hibernate 再接触 树状结构设计以及学生课程成绩表的设计
1 树状结构的设计 package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax. ...
- 通过学生-课程关系表,熟悉hive语句
通过学生-课程关系表,熟悉hive语句 1.在hive中创建以下三个表. create table student(Sno int,Sname string,Sex string,Sage int, ...
- Mysql学生管理系统:表的建立,外键一对多,多对多关系,中间关联表的建立
学生管理系统 管理员注册/登录/注销 注册班级(班级详细信息) 注册学生信息 查看班级信息/查看老师资料 教师注册/注销 查看教师资料 查看学生资料 根据名称/班级/ 查看学生详细信息--支持模 ...
- hibernate 映射实例 学生 课程 成绩
学生和课程是多对多,一个学生的一个课程只能对应一个成绩. 所以学生和课程多对多,其中间表多了一个成绩字段. 可以这样设计: 学生和课程通过中间表--成绩,多对多映射. 手动建中间表语句: cr ...
- mysql添加为成绩表添加名次
对于一种这样的表,为score添加名次
- hibernate实现学生-课程-成绩
1.实体类Student package com.test.model; import javax.persistence.Entity; import javax.persistence.Gener ...
- Javaweb 第5天 mysql 数据库课程
MySQL数据库课程 两日大纲 ● 数据库的概念.MySQL快速入门.SQL语言简介 ● 数据库操作.表操作.数据记录操作.数据类型和约束 ● 查询 ● 多表关系.多表连接查询 ● 视图 ● 数据备份 ...
- Django 小实例S1 简易学生选课管理系统 11 学生课程业务实现
Django 小实例S1 简易学生选课管理系统 第11节--学生课程业务实现 点击查看教程总目录 作者自我介绍:b站小UP主,时常直播编程+红警三,python1对1辅导老师. 课程模块中,学生需要拥 ...
- 小菜菜mysql练习解读分析1——查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数
查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 好的,第一道题,刚开始做,就栽了个跟头,爽歪歪,至于怎么栽跟头的 ——需要分析题目,查询的是 ...
随机推荐
- Jquery 实现原理之 Ajax
一:Jquery Ajax底层接口有:$.ajaxPrefilters.$.ajaxTransport.$.ajaxSettings.$ajaxSetup.$ajaxSettings; 其中$.aja ...
- linux内核移植到S5pv210
make s5pv210_defconfig 1.System Type ---> (0) S3C UART to use for low-level messages 2.Kernel ha ...
- andorid 自定义view属性declare-styleable
1. reference:参考某一资源ID. (1)属性定义: <declare-styleable name = "名称"> <attr name = &quo ...
- Node.js学习 - Modules
创建模块 当前目录:hello.js, main.js // hello.js exports.world = function() { // exports 对象把 world 作为模块的访问接口 ...
- CodeForces 567B Berland National Library
Description Berland National Library has recently been built in the capital of Berland. In addition, ...
- 二分图最大匹配 Hopcroft-Karp算法模板
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> ...
- Day05_JAVAEE系列:XML
XML概述 1)什么是xml? xml, eXtend Markup Language, 可扩展标记语言 2) html vs xml 都由w3c组织制定的. html语法特征:语法比较松散 ...
- zf-关于查询机把index.jsp换成index_new.jsp页面之后把功能链接都改成新页面的简单方法
一开始我都是找action 然后一个一个的改 把onmousedown="goURL('index.jsp')" 改成 onmousedown="goURL('index ...
- 让shell 变得容易理解
1.重建你的语义模型(简单语义模型)2.变量,参数和方法命名3.测试用例4.足够的组块
- dom4j解析xml实例
dom4j是一个java的XML API,类似jdom,用来读写XML文件,它性能优异.功能强大和极易使用等特点 所用jar包:dom4j-1.6.1.jar 需要解析的xml文件:people.xm ...