设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8156|回复: 15

YY4350 SQL 课后习题 (持续更新)

[复制链接]

3

主题

5

好友

304

积分

中级会员

Rank: 3Rank: 3

性别
保密

最佳新人 活跃会员 热心会员 灌水之王 优秀版主

发表于 2013-6-5 20:47:49 |显示全部楼层
大家可以把答案跟在后面的楼,我会在下次上课之前都批改一遍。
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)。

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
发表于 2013-6-6 18:50:12 |显示全部楼层
create table student(
      s_id int primary key not null,
     s_name varchar(20),
    s_age int ,

)
回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
发表于 2013-6-6 18:54:11 |显示全部楼层
创建表:
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
)
回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
发表于 2013-6-6 18:55:41 |显示全部楼层
本帖最后由 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;

回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
发表于 2013-6-6 19:00:08 |显示全部楼层
(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";
回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
发表于 2013-6-6 19:00:16 |显示全部楼层
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

下班回家。、

回复

使用道具 评分 举报

22

主题

8

好友

1898

积分

超级版主

Rank: 8Rank: 8

生肖
星座
天秤座
性别

最佳新人 活跃会员 热心会员 灌水之王 突出贡献 优秀版主

发表于 2013-6-6 22:35:30 |显示全部楼层
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
回复

使用道具 评分 举报

22

主题

8

好友

1898

积分

超级版主

Rank: 8Rank: 8

生肖
星座
天秤座
性别

最佳新人 活跃会员 热心会员 灌水之王 突出贡献 优秀版主

发表于 2013-6-6 22:51:13 |显示全部楼层
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

我好闲啊
人都有一段故事,没有精彩与否,只有感人与否
回复

使用道具 评分 举报

150

主题

5

好友

1179

积分

管理员

Rank: 9Rank: 9Rank: 9

性别
保密

最佳新人 活跃会员 推广达人 宣传达人 突出贡献 优秀版主 论坛元老

发表于 2013-6-7 08:15:22 |显示全部楼层
感觉这个帖子有技术讨论的气氛
回复

使用道具 评分 举报

3

主题

5

好友

304

积分

中级会员

Rank: 3Rank: 3

性别
保密

最佳新人 活跃会员 热心会员 灌水之王 优秀版主

发表于 2013-6-8 08:02:52 |显示全部楼层
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

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

回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 立即注册


手机版|SKY外语计算机学习 ( 粤ICP备12031577 )    

GMT+8, 2024-3-29 15:54 , Processed in 0.194267 second(s), 27 queries .

回顶部