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 "课程成绩高的学生的信息及课程分数 好的,第一道题,刚开始做,就栽了个跟头,爽歪歪,至于怎么栽跟头的 ——需要分析题目,查询的是 ...
随机推荐
- POJ 2082Lost Cows<>
题意: 给出一个序列a[1....n],a[i]代表在0....i-1中比a[i]小的个数. 求出这个序列. 思路: 1:暴力. #include<cstdio> #include< ...
- 线程访问 DevExpress控件异常时 解决方法
Control.CheckForIllegalCrossThreadCalls = false; DevExpress.Data.CurrencyDataController.DisableThrea ...
- Log4j NDC MDC
NDC(Nested Diagnostic Context)和MDC(Mapped Diagnostic Context)是log4j种非常有用的两个类,它们用于存储应用程序的上下文信息(contex ...
- android TextView 之探究
1:插入图片替换 //代码 mSubjectDetailView = (TextView) findViewById(R.id.subject_detail); CharSequence text = ...
- android代码实现免提功能
初始化AudioManager: private static AudioManager audioManager; 实现免提功能方法 protected void setSpeekModle() { ...
- 利用未文档化API:RtlAdjustPrivilege 提权实现自动关机
这里主要是利用NTDLL.dll中未文档化的API: RtlAdjustPrivilege 来实现提权.自动关机的功能. RtlAdjustPrivilege定义如下: NTSTATUS RtlAdj ...
- Warning: Cannot modify header information - headers already sent by ... functions_general.php on line 45
摘自:有用到 http://blog.csdn.net/besily/article/details/5396268 PHP错误:Warning: Cannot modify header infor ...
- Servlet程序开发--取得初始化配置信息
代码: 两个初始化init方法,一起出现的话,有参的才起作用 package org.lxh.servletdemo ; import java.io.* ; import javax.servlet ...
- hprof网络连接
demo/jvmti/hprof/tt/manual.htmlnc -l -k 12321 java -agentpath:./demo/jvmti/hprof/lib/libhprof.so=net ...
- gen_grant_exec.sql
set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee = & ...