设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: SKY闫喔喔
打印 上一主题 下一主题

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

[复制链接]

22

主题

8

好友

1898

积分

超级版主

Rank: 8Rank: 8

生肖
星座
天秤座
性别

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

7#
发表于 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
回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
6#
发表于 2013-6-6 19:00:16 |只看该作者
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑

下班回家。、

回复

使用道具 评分 举报

9

主题

0

好友

164

积分

注册会员

Rank: 2

性别
保密
5#
发表于 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 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 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:50:12 |只看该作者
create table student(
      s_id int primary key not null,
     s_name varchar(20),
    s_age int ,

)
回复

使用道具 评分 举报

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


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

GMT+8, 2024-5-19 01:19 , Processed in 0.098636 second(s), 25 queries .

回顶部