暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
数据库.docx
379
49页
4次
2021-02-23
免费下载
以下答案可能存在错误,敬请谅解!
数据库
1
.数据库基础
1.1 Sql
语句
1.1.1
3
个表(
15
分钟)
Student
学生表
(
学号,姓名,性别,年龄,组织部门
)
Course
课程表
(
编号,课程名称
)
Sc
选课表
(
学号,课程编号,成绩
)
表结构如下:
1
写一个
SQL
语句,查询选修了’计算机原理’的学生学号和姓名(
3
分钟)
Select sno,sname from Student where sno in (Select sno from Sc where cno = (Select cno
from Course where cname = ‘
计算机原理’
))
2
写一个
SQL
语句,查询’周星驰’同学选修了的课程名字(
3
分钟)
Select cname from course where con in (select cno from Course whert sno = (select sno
from Student where name = ‘
周星驰’
) )
3
写一个
SQL
语句,查询选修了
5
门课程的学生学号和姓名(
9
分钟)
Select sno,name from Student where (select count(*) from Sc where sno=Student.sno ))
=5;
答:
1
SQL
语句如下:
select stu.sno, stu.sname from Student stu
where (select count(*) from sc where sno=stu.sno and cno =
(select cno from Course where cname='
计算机原理
')) != 0;
2
SQL
语句如下:
select cname from Course
where cno in ( select cno from sc where sno =
(select sno from Student where sname='
周星驰
'));
3
SQL
语句如下:
select stu.sno, stu.sname from student stu
where (select count(*) from sc where sno=stu.sno) = 5;
以下答案可能存在错误,敬请谅解!
1.1.2
,
S,
C,
SC,
多门课程
,
一门课程可以被多个学生选修
,
通过
SC
表关联。
1
)写出建表语句;
Create table S (
Id int auto_incretment primary key,
name varchar(20);
)
Create table C(
Id int auto_increment primary key,
Name varchar(20)
)
Create table SC(
Sid int foreign key references S(id),
Cid int foreign key references S(id),
)
2
写出
SQL
语句
,
查询选修了所有选修课程的学生;
Select name from S where ((select count(*) from SC where Sid=S.id)=(select count(*) from
C))
3
写出
SQL
语句
,
查询选修了至少
5
门以上的课程的学生。
Select name from S where id in (select sid from Sc where (select count(*) from SC where
C.id=SC.Cid) > 5))
Select name from s where (select count(*) from sc where sc.sid =s.id ) >= 5
答:
1
)建表语句如下(
mysql
数据库):
create table s(id integer primary key, name varchar(20));
create table c(id integer primary key, name varchar(20));
create table sc(
sid integer references s(id),
cid integer references c(id),
primary key(sid,cid)
);
2
SQL
语句如下:
select stu.id, stu.name from s stu
where (select count(*) from sc where sid=stu.id)
= (select count(*) from c);
3
SQL
语句如下:
select stu.id, stu.name from s stu
where (select count(*) from sc where sid=stu.id)>=5;
108
、数据库表
(Test)
结构如下:【基础】
of 49
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜