设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8649|回复: 1
打印 上一主题 下一主题

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

[复制链接]

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

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

使用道具 评分 举报

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


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

GMT+8, 2024-5-3 12:49 , Processed in 0.131538 second(s), 26 queries .

回顶部