SKY外语计算机学习

标题: YY4350 SQL 课后习题 (持续更新) [打印本页]

作者: SKY闫喔喔    时间: 2013-6-5 20:47
标题: YY4350 SQL 课后习题 (持续更新)
大家可以把答案跟在后面的楼,我会在下次上课之前都批改一遍。
YY4350 SQL 每周三晚20:00

1
、设有一个学生管理数据库,有三个基本表,表结构如下:
学生表student(学号,姓名,年龄,性别,系号)
课程表course(课程号,课程名,学时数)
选修表sc(学号,课程号,成绩)
(1)请写出使用create table…命令创建student表的命令序列。
(2)请用SQL语言检索信息系(系号为‘06’)学生的学号,姓名,课程号和成绩。
(3)请用SQL语言检索比学号‘S1’大3岁的学生的学号,姓名和年龄。
(4)请用SQL语言检索选修全部课程的学生姓名。
(5)请用SQL语言检索选修课程在10门以上的学生的系号,学号,姓名,最低分,最高分,平均分和选课门数,其结果要求按照系号,平均分排序。
(6)请用SQL语言检索至少选修了‘数据库’和‘C语言’这两门课的学生信息。
(7)请用SQL语言检索与学号为‘S1’同在一个系的学生的姓名及各门课程和成绩。
(8)删除选修表中成绩不及格的记录。
(9)将“数据库”课程的学时数改为84学时。
(10)向课程表中插入一门课程(‘14’,‘UNIX操作系统’,84)。

作者: 回忆搁浅    时间: 2013-6-6 18:50
create table student(
      s_id int primary key not null,
     s_name varchar(20),
    s_age int ,

)
作者: 回忆搁浅    时间: 2013-6-6 18:54
创建表:
create table student(
     s_id int primary key not null,
    s_name varchar(20),
     s_age int,
    s_sex varchar(10),
    s_x int
)

create table course
(
    cs_id int primary key not null,
    cs_name varchar(20),
   cs_keshishu  int
)


create table sc
(
    sc_id int primary key not null ,
   s_id int references studen(s_id),
   cs_id int references course(cs_id),
sc_score int
)
作者: 回忆搁浅    时间: 2013-6-6 18:55
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

创建序列
create seqence seq_stu
start with 1
incrment by 1;
create sequence seq_cousre
start with 10
incrment by 1;
create sequence seq_sc
start with 1001
increment by 1;


作者: 回忆搁浅    时间: 2013-6-6 19:00
(2)select a.s_id , a.s_name , c.sc_id, c.sc_score from student a inner join sc c on
c.s_id = a.s_id where a.s_x="06";

作者: 回忆搁浅    时间: 2013-6-6 19:00
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

下班回家。、


作者: 小卢_铃    时间: 2013-6-6 22:35
1.
create table Student
(
  Stu_ID char(10),
  Stu_Name char(8),
  Sage int,
  Ssex char(2),
  Sdeptno int,
  primary key(Stu_ID)
  )


create table Course
(
  Course_ID char(10),
  Course_Name char(8),
  Chours int,
  primary key(Course_ID)
  )

  create table SC
  (
    Stu_ID char(10),
    Course_ID char(10),
    score float,
    primary key(Stu_ID,Course_ID),
    foreign key(Stu_ID) references Student(Stu_ID),
    foreign key(Course_ID) references Course(Course_ID)
   )

2.
select Stu_ID,Stu_Name,Course_ID,score
from Student,sc
where Sdeptno='o6'

3.
select Stu_ID,Stu_Name,Sage
from Student
where (Sage-3)=(select Sage from Student Stu_ID='S1')

4.
select Stu_Name
from Student
where not exists
      (select Course_ID
      from Course
      where not exists
             (select *
             from SC
             where SC.Course_ID =Course.Course_ID and
             SC.Stu_ID=Student.Stu_ID )
           )

5.
select Sdeptno,Student.Stu_ID,Stu_Name,min(score),max(score),avg(score),count(*)
from Student,SC
where Student.Stu_ID=SC.Stu_ID
group by Student.Stu_ID
having conut(*)>=10
order by Sdeptno,avg(score) desc
作者: 小卢_铃    时间: 2013-6-6 22:51
6.
select Student.Stu_ID
from Student,SC
where Student.Stu_ID=SC.Stu_ID and SC.Course_ID='数据库' or Student.Stu_ID=SC.Stu_ID and SC.Course_ID='C语言’
group by Student.Stu_ID

我好闲啊
作者: Kill    时间: 2013-6-7 08:15
感觉这个帖子有技术讨论的气氛
作者: SKY闫喔喔    时间: 2013-6-8 08:02
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

感觉这个帖子有技术讨论的气氛[/quote]
你歪楼了!!讨厌!


作者: SKY闫喔喔    时间: 2013-6-8 08:03
小卢_铃 发表于 2013-6-6 22:51
6.
select Student.Stu_ID
from Student,SC

不啊不啊  这又不是灌水  大铃子 么么哒
作者: SKY闫喔喔    时间: 2013-6-8 08:05
回忆搁浅 发表于 2013-6-6 19:00
下班回家。、

么么哒
作者: 格式化    时间: 2013-6-13 22:01
重要的是 他们都好用功!
作者: 白蚁    时间: 2013-6-20 13:01
支持闫喔喔妹纸,你们大家一定要跟着闫喔喔妹纸好好学习哟~
作者: rogan    时间: 2013-6-20 22:32
  1. CREATE TABLE `student` (
  2.   `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '学号',
  3.   `name` text COMMENT '姓名',
  4.   `age` int(11) DEFAULT NULL COMMENT '年龄',
  5.   `sex` text COMMENT '性别',
  6.   `class` int(11) DEFAULT NULL COMMENT '系号',
  7.   PRIMARY KEY (`id`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

  9. CREATE TABLE `course` (
  10.   `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '课程号',
  11.   `coursename` text COMMENT '课程名',
  12.   `coursenum` int(11) DEFAULT NULL COMMENT '学时数',
  13.   PRIMARY KEY (`id`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

  15. CREATE TABLE `sc` (
  16.   `studentid` int(11) DEFAULT NULL COMMENT '学生号',
  17.   `courseid` int(11) DEFAULT NULL COMMENT '课程号',
  18.   `grade` int(11) DEFAULT NULL COMMENT '成绩',
  19.   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  20.   PRIMARY KEY (`id`)
  21. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
复制代码

作者: rogan    时间: 2013-6-20 22:45
如果有实例数据就更好了




欢迎光临 SKY外语计算机学习 (http://skywj.com/) Powered by Discuz! X2.5